jquery - .animate({ width: 'toggle' }) without messing up the content -
so i'm having problem left-sliding div. i'm using $('#searchbox').animate({ width: 'toggle' });
show it, while sliding looks the content inside of gets float ignored. fixed after div stops sliding, it's weird effect while slides. codes i'm using:
// 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 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; }
i know workaround problem using absolute positions on #magnifier
, #searchboxinput
, .closebutton
, wouldn't me. there other way this?
fiddle: http://tinker.io/ef4f7
it behaving because of width. doesn't have enough width show items floating on same line. there no enough width show them. instead can toggle right position.
demo
function searchbar() { $('#searchbox').animate({ right: 'toggle' }); $('#searchboxbutton').fadetoggle('fast'); } function searchbarclose() { $('#searchbox').animate({ right: 'toggle' }); $('#searchboxbutton').fadetoggle('fast'); }
with slide effect
demo
function searchbar() { $('#searchbox').show('slide', { direction: 'right' }, 2000); $('#searchboxbutton').fadetoggle('slow'); } function searchbarclose() { $('#searchbox').hide('slide', { direction: 'right' }, 2000, function () { $('#searchboxbutton').fadetoggle('slow'); }); }
Comments
Post a Comment