jquery - slide on iphone safari causes toggle to fire bug -
on http://inigo.nu (temporary project)
i use clicking div toggle display menu ul using
html:
<div id="toggle-menu" class="hover">menu</div>
jquery:
jquery(document).ready(function(jquery) { jquery('#toggle-menu').on('click', function() { jquery('nav ul').toggle('slow'); }); });
only on iphone safari strange bug occurs.
sliding after opening menu click makes opened menu dissappear again. causes strange behavior , how can fix it?
sadly post: safari browser (iphone simulator): how see/monitor events being triggered? never answered. cause see triggered events.
i console.log ed slide event didn't clear things my.
so side question how best debug such issue.
i installed developer on safari desktop , have no js errors. on slide display set inline none onclick. there no padding or overlay issues going on.
any appreciated.
i found question when working on solving same issue client of mine. client has mobile navigation revealed when "toggle icon" clicked. script used .toggle()....which yes deprecated function of jquery 1.9 (client using 1.7.2 , can't switch it), replicate exact problem described using both toggle/slidetoggle.
i'll explain solution in detail , label sections may want skip.
script used
the script editing fix problem navigation. "toggle" event display nav area , checks if browser @ mobile width (if not, hides of mobile elements).
attempted solutions/steps taken
i tried switch toggle() slidetoggle(), see happen. no surprise, issue same.
i switched more optimal approach toggling display class on relevant elements. appeared work fine, led same problem: moment scroll on ipad class reverted itself.
the solution
this me interesting, because script click event, yet firing on scroll.
as noted above, there resize function supposed rehide stuff when browser got above mobile breakpoint. original resize function sub-optimal imo, opted update it on hunch.
old
$(window).resize(function() { if( $(window).width > 700 ) { $(".visible").removeclass("visible"); } });
new
$(window).resize(function() { if ( $(window).matchmedia('(min-width: 788px)').matches ) { $(".visible").removeclass("visible"); } });
using matchmedia turned out needed along. kept class toggles though :).
but again, in god's name cause resize trigger on scroll? according jquery team, bug safari/ios associated .resize(). note: it's not jquery bug, issue relates event.
source: http://bugs.jquery.com/ticket/14119
note responder indicates issue resolved when uses pojo event listener vs jquery equivalent. example provide doesn't deal matchmedia, think can extrapolate what's happening:
my theory
i believe safari triggering jquery's .resize() event on scroll incorrectly, causing script fire when shouldn't. believe issue solved match media because if script re-fires, won't since matchmedia statement evaluates false, vs looking @ window width via $(window).width().
either way hope helps or else somehow.
Comments
Post a Comment