css - jquery setting z-index before toggleClass -
tying produce proof of concept function, ignore terrible naming conventions! ;-)
i have jsfiddle here http://jsfiddle.net/dde8d/
$(document).ready(function () { $('#commission_1').on('click', function () { var newzindex = -1; if ($('#searchform_1').hasclass('showfrm')) { $('#searchform_1').css("z-index", newzindex); /* remove comment below make work */ /*$('#searchform_1').delay(750);*/ /*it chained on line above */ } $('#searchform_1').toggleclass("showfrm", 500, function () { if ($('#searchform_1').hasclass('showfrm')) { newzindex = 100; } $('#srchtext1').toggleclass("shrt", 500, function () { $('#commission_1').toggleclass("btn-success").toggleclass("btn-primary", 1000, function () { $('#comm-icon-1').toggleclass("glyphicon-chevron-right").toggleclass("glyphicon-chevron-left"); $('#searchform_1').css("z-index", newzindex); }); }); }); }); });
the effect trying achieve is:- user pushes button, input form 'slides out' behind button user pushes button again, form 'slides back' behind button.
this fiddle working, 750ms delay after changing z index.
why this? there documented reason z-index not change immediately.
note: included jquery ui allow completion functions on toggleclass. have affected it?
thanks
<style> .srchfrm { float: left; left: -87px; position: relative; top: -32px; z-index: -5; } .showfrm { left: 96px; margin: 0 !important; position: relative; top: -32px; transition: 0.5s linear 0s; width: 300px; } .btn.btn-success { border: 1px solid #ff0000; float: left; padding: 10px; position: relative; z-index: 5; } .search { background-color: #f0f0f0; border: 1px solid #dddddd; height: 51px; left: 10px; overflow: hidden; padding: 4px 4px 4px 0; position: relative; transition: 0.5s linear 0s; width: 392px; z-index: 10; } </style> <script> $(document).ready(function () { $('#commission_1').on('click', function () { $('#searchform_1').toggleclass("showfrm"); }); }); </script> <body> <h1>hello, world!</h1> <div class="search"> <button type="button" class="btn btn-success" id="commission_1">commission</button> <form action="#" name="searchform" method="get" id="searchform_1" class="srchfrm"> <input type="text" name="s" maxlength="64" id="searchform" value="" class="text-comm-email" /> <input type="button" value="go" /> </form> </div> </body>
Comments
Post a Comment