Monday, 15 June 2015

jQuery - prevent same click function to run more than once at a time -


I just started to start javascript and jquery, and my first problem is that I have real headache. I am searching for hours to solve it, but none of the solutions work.

My problem is this: I have created a "carousel" website, where the content has been omitted Or right, if the menu is clicked on the link.

Everything works fine, but if you click on, another menuulin has finished again before the click function's animation, the content has been slammed and is not in the correct position.

I promised (). Did not work for me (), flags, callback and so on, but nothing worked for me :( Maybe I did it wrong ..

I'm searching for a solution, until it's over Or it is better to make a queue of this celebration, move after each other, but not at the same time.

This is my JS code, I know that this is not right and better Can be solved, but as I said, today I started learning these things And I am not familiar with the syntax, and so on.

  var getoPage = function (pos) {if (pos == 'home') {$ ('li Css ({"left": "1700px"}) $ ('li #home'). Chetan ({" $ ('Left # news'). Chetan ({"left": "-1700 px"}, speed,' camerainte quest '); $ (' Chetan ({"left": "-1700 px"}, speed, 'Kamiren Quest'); Chetan ({"ambiguity": 0}, 0); $ ('Li # Gallery'). $ ('Li # Gallery'). Animate ({"Opacity": 0}, 0);} and A And (pos == 'news') {$ ( 'li # news'). Css ({ "ambiguity": 1}); $ ('Li # News'). CSS ({"left": "1700px"}); $ ('Li # News'). Animate ({"left": "0px"}, speed, 'easeinOutQuint'); $ ('Lee # Home') Chetan ({"left": "-1700px"}, speed, 'easeinOutQuint'); $ ('Lee # Home') Animate ({"opacity": 0}, 0); $ ('Li # Gallery'). Chetan ({"left": "-1700 px"}, speed, 'camerainte quest'); $ ('Li # Gallery'). Animate ({"opacity": 0}, 0); } Else if (pos == 'galery') {$ ('li # galery'). CSS ({"Opacity": 1}); $ ('Li # Gallery'). CSS ({"left": "1700px"}); $ ('Li # galery') Animate ({"left": "0px"}, speed, 'easeinOutQuint'); $ ('Li # News'). Chetan ({"left": "-1700px"}, speed, 'Kamiren Quest'); $ ('Li # News'). Animate ({"opacity": 0}, 0); $ ('Lee # Home') Chetan ({"left": "-1700px"}, speed, 'easeinOutQuint'); $ ('Lee # Home') Animate ({"opacity": 0}, 0); }} $ (Document) .ready (function () (hide) All (); AutoSeat (); $ ('# Home') Click (function () {Goto page (poshom);}) $ ('# Click '). Click (function () {Goto page (Poznews);}); $ (' # gallery). '(Function () {Goto page (PauseGallery);}}}});   

Can you please help me?

The answer to Brad Greens is most accurate.

Here's an option for fun:

You can tell whether the animation is still performing or not, you can "currently" again after the animation is complete, Set to false;

  var animating = false if (pos == 'home' & amp; animating) {animating = true; $ ('Li # Gallery'). Animate ({"opacity": 0}, 100, function () {// animation complete. Animating = false;});); }    

No comments:

Post a Comment