Temporarily Disallow JQuery Toggle
- by Kevin Sylvestre
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.