jquery - how to avoid endless animation triggered by multiple clicks on menu item -
i working on second site decided utilize jquery. got problem , can't resolve , neither find out solution on web.
so, created 1 page site has menu , each item of triggers animation (horizontal movement + fadeout). clicking on second/third or fifth link, initial home page animations fading out, while clicking on "home", animations/images/etc. returning proper-initial places. though, if click on "home" twice or ten times, on each click, horizontally animated stuff moving endless assigned distances.
so, questions are: 1. how should resolve problem - endless animation multiple clicks on "home" menu item; 2. how make other menu items work , find animated objects in initial places clicking on "home"?
here code. sorry if find mess here - green in jquery. thank in advance :)
<div id="nav"> <ul class="nav"> <li id="home"><a class="active" href="#">home</a></li> <li id="stylist"><a href="#">hair stylist</a></li> <li id="salon"><a href="#">salon</a></li> <li id="center"><a href="#">dibi center</a></li> <li id="gallery"><a href="#">gallery</a></li> <li id="press"><a href="#">press</a></li> <li id="check"><a href="#">check up</a></li> </ul> </div> $(document).ready(function() { var nav_0 = $("li#home") var nav_1 = $("li#stylist") var rot1 = $("#rotate_1") var rot2 = $("#rotate_2") var rot3 = $("#rotate_3") var rot4 = $("#rotate_4") var rot5 = $("#rotate_5") var initialpage = $("#fade") nav_0.click(function(){ initialpage.fadein(1500); rot1.animate({"left": "-=20%", "opacity": "1"}, 1000); rot2.animate({"top": "-=400px", "opacity": "1"}, 1000); rot4.fadein(2000); rot5.animate({"left": "+=200px", "opacity": "1"}, 1000); rot3.animate({"top": "+=300px", "opacity": "1"}, 1000); }); nav_1.click(function(){ initialpage.fadeout(2000); rot1.animate({"left": "+=20%", "opacity": "0"}, 1500); rot2.animate({"top": "+=400px", "opacity": "0"}, 1500); rot4.fadeout(800); rot5.animate({"left": "-=200px", "opacity": "0"}, 1500); rot3.animate({"top": "-=300px", "opacity": "0"}, 1500); }); });
how checking see if menu animating:
if($('.menuclass:animated').length == 0){ *do animation . . .* }
this check see of '.menuclass' animated, if isn't, kick off animation. if animated, nothing.
Comments
Post a Comment