3

そのため、左スライドの div に問題があります。現在、私は$('#searchBox').animate({ width: 'toggle' });それを表示するために使用していますが、スライドしている間、その中のコンテンツがフロートを無視しているように見えます。div のスライドが止まると修正されますが、スライド中の奇妙な効果です。私が使用しているコード:

// Search bar dropdown script

    function searchBar() {
        $('#searchBox').animate({ width: 'toggle' });
        $('#searchBoxButton').fadeToggle('fast');
    }

    function searchBarClose() {
        $('#searchBox').animate({ width: 'toggle' });
        $('#searchBoxButton').fadeToggle('fast');
    }

<div id="searchBoxButton" onclick="searchBar()"></div>
<div id="searchBox">
    <form>
        <div id="magnifier"></div>
        <input id="searchBoxInput" placeholder="Search me" type="text"/>
        <div class="closeButton" onclick="searchBarClose()"></div>
    </form>
</div>

    #searchBoxButton {
    width: 50px;
    height: 50px;
    background-color: #000;
    right: 0;
    position: absolute;
    margin: -5px auto 0 auto;
}

#searchBox {
    display: none;
    right: 0;
    position: fixed;
    margin: -5px auto 0 auto;
    background-color: #202020;
    z-index: 1;
    padding: 3px 0;
    border: 1px solid #151515;
}

#searchBox input[type="text"] {
    width: 150px;
    outline: none;
    padding: 3px 2px;
    background-color: #3F3F3F;
    border: 1px solid #4d4d4d;
    border-radius: 3px;
    font-family: "Trebuchet MS" sans-serif;
    color: #c0c0c0;
    float:left;
}

#searchBox input[type="text"]:focus {
    border: 1px solid #797979;
    box-shadow: 0px 0px 15px -2px #797979;
    background-color: #444444;
}

#searchBoxInput::-webkit-input-placeholder { /* WebKit browsers */
    color:    #7d7d7d;
}
#searchBoxInput:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
    color:    #7d7d7d;
}
#searchBoxInput::-moz-placeholder { /* Mozilla Firefox 19+ */
    color:    #7d7d7d;
}
#searchBoxInput:-ms-input-placeholder { /* Internet Explorer 10+ */
    color:    #7d7d7d;
}

#magnifier {
    background: url("http://placehold.it/13x13") no-repeat;
    width: 13px; height: 13px;
    float: left;
    margin: 7px 6px;
}

.closeButton {
    border-radius: 15px;
    cursor: pointer;
    background: url("http://placehold.it/15x15") center no-repeat;
    width: 15px; height: 15px;
    float: left;
    -webkit-transition: background 200ms ease-in-out;
    -moz-transition: background 200ms ease-in-out;
    -o-transition: background 200ms ease-in-out;
    transition: background 200ms ease-in-out;
}

#searchBox .closeButton {
    margin: 7px 4px;
    float: left;
}

.closeButton:hover {
    background-color: #373737;
    -webkit-transition: background 200ms ease-in-out;
    -moz-transition: background 200ms ease-in-out;
    -o-transition: background 200ms ease-in-out;
    transition: background 200ms ease-in-out;
}

.closeButton:active {
    background-color: #212121;
}

#magnifierこの問題の回避策は、 、#searchBoxInputおよびで絶対位置を使用すること.closeButtonですが、それは私にとっては良くありません。これを行う他の方法はありますか?

フィドル: http://tinker.io/ef4f7

4

2 に答える 2

3

Here is a jsfiddle functioning more like you want using width instead of right. Note I changed some of your CSS and excluded the search button itself as I didn't have access to that image. But in short here is the main fix:

function searchBar() {
        $('input').fadeIn('fast', function () {
          $('#searchBox').animate({ width: 'toggle' });
      });

}

See you need that input box width so that you don't have the sizing issue. the above should work and here is the jsfiddle

NOTE: there is an extra anchor there just to demo again as I didn't have access to your magnifier button but you should get the idea. Let me know if its not functioning as you'd like.

于 2013-05-20T03:42:11.587 に答える