Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery - prevent same click function to run more than once at a time
    primarykey
    data
    text
    <p>I just started to lern JavaScript and jQuery today, and got my first problem wich causes me real headache. I've been searching for hours to solve this, but none of the solutions did work. </p> <p>My problem is: I made a "carousel" website, where content is slided left or right, if clicked on a menu link.</p> <p>Everything works fine, but if u click on another menulink again before the animation of the click function has finished, the content slides away and is not at the right position.</p> <p>I've tryed promise().done(), flags, callback and so on, but nothing worked for me :( maybe I did it just wrong..</p> <p>I'm searching for a solution, to block this click function until it finishes, or better making a queue of this function, to run after another, but not at the same time.</p> <p>Here is my JS code, I know it's not perfect and could be solved better, but like I said, i just started to learn this stuff today and I'm not yet familiar with the syntax and so on.</p> <pre><code> var gotoPage = function(pos) { if(pos == 'home') { $('li#home').css({"opacity" : 1}); $('li#home').css({"left" : "1700px"}); $('li#home').animate({"left" : "0px"}, speed, 'easeInOutQuint'); $('li#news').animate({"left" : "-1700px"}, speed, 'easeInOutQuint'); $('li#news').animate({"opacity" : 0}, 0); $('li#galery').animate({"left" : "-1700px"}, speed, 'easeInOutQuint'); $('li#galery').animate({"opacity" : 0}, 0); } else if (pos == 'news') { $('li#news').css({"opacity" : 1}); $('li#news').css({"left" : "1700px"}); $('li#news').animate({"left" : "0px"}, speed, 'easeInOutQuint'); $('li#home').animate({"left" : "-1700px"}, speed, 'easeInOutQuint'); $('li#home').animate({"opacity" : 0}, 0); $('li#galery').animate({"left" : "-1700px"}, speed, 'easeInOutQuint'); $('li#galery').animate({"opacity" : 0}, 0); } else if (pos == 'galery') { $('li#galery').css({"opacity" : 1}); $('li#galery').css({"left" : "1700px"}); $('li#galery').animate({"left" : "0px"}, speed, 'easeInOutQuint'); $('li#news').animate({"left" : "-1700px"}, speed, 'easeInOutQuint'); $('li#news').animate({"opacity" : 0}, 0); $('li#home').animate({"left" : "-1700px"}, speed, 'easeInOutQuint'); $('li#home').animate({"opacity" : 0}, 0); } } $(document).ready(function(){ hideAll(); autoSelect(); $('#home').click(function(){ gotoPage(posHome); }); $('#news').click(function(){ gotoPage(posNews); }); $('#galery').click(function(){ gotoPage(posGalery); }); }); </code></pre> <p>Can you please help me?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload