javascript - Jquery bug dblclick/click -
i've been experimenting jquery , have come upon problem. http://javascript.nicklewers.co.uk/nav/
on 'android' tab i've set if click once, sub menu appear, when doubleclicking, main content appear.
now problem is: double click involves 2 single clicks involves sub menu opening , closing , looks bad. how prevent this?
try (using timer know if single click or double):
alreadyclicked=false; $('#android').bind('click',function(){ var el=$(this); if (alreadyclicked) { alreadyclicked=false; // reset cleartimeout(alreadyclickedtimeout); // prevent happening // needs happen on double click. } else { alreadyclicked=true; alreadyclickedtimeout=settimeout(function(){ alreadyclicked=false; // reset when happens // needs happen on single click. // use el instead of $(this) because $(this) // no longer element },300); // <-- dblclick tolerance here } return false; });
Comments
Post a Comment