Temporarily Disallow JQuery Toggle
Posted
by Kevin Sylvestre
on Stack Overflow
See other posts from Stack Overflow
or by Kevin Sylvestre
Published on 2010-06-10T18:59:17Z
Indexed on
2010/06/10
19:02 UTC
Read the original article
Hit count: 179
jQuery
I have a menu that is toggled when a user selects a link. The menu has an animation attached, and I want to prevent toggling while the animation is running. The following snippet works, but flips the state of toggle if the link is clicked quickly twice (i.e. if the user clicks the link quickly twice, the next click will trigger the same action):
<a href="" id="button">Menu</a>
<div id="menu">...</a>
<script>
$("#button").toggle(
function (e) {
if $("#menu").is(":animated")) return false;
$menu.show("slow");
},
function (e) {
if ("#menu").is(":animated")) return false;
$menu.hide("slow");
}
);
</script>
How can I prevent switching states within toggle?
Thanks.
© Stack Overflow or respective owner