Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clicking too fast with slide gallery (jquery)

$(document).ready(function(e) {

$('span#pijlr').click(function(e) {
    var slide = 500;
    var variable = $('#gallcont').css('left');
    var urechts = "-1000px";
    if(variable > urechts) {
    $('#gallcont').animate({'left': '-=' +slide+ 'px'},'fast','linear');
    }
});

$('span#pijll').click(function(e) { 
    var slide = 500;
    var variable = $('#gallcont').css('left');
    var ulinks = "0px";
    if(variable < ulinks) {
    $('#gallcont').animate({'left': '+=' +slide+ 'px'},'fast','linear');
    }   
}); 




});

This code i wrote for a simple slide gallery i made. All works fine except when i fast click the arrow buttons. It will go beyond the values i set up (urechts and ulinks).

I tried putting 'stop()' before the .animate, but it didn't help. Hope you guys can give me some advise on how to solve this. Thanks in advance!

like image 723
Seltjoek Avatar asked Jan 16 '12 22:01

Seltjoek


1 Answers

What about adding some conditional, like this:

$('span#pijlr').click(function(e) {
    if (!$('#gallcont').is(':animated')) {
        var slide = 500;
        var variable = $('#gallcont').css('left');
        var urechts = "-1000px";
        if(variable > urechts) {
        $('#gallcont').animate({'left': '-=' +slide+ 'px'},'fast','linear');
        }
    }
});

Something like that will nullify the event while the slide is animating..

like image 64
ezakto Avatar answered Sep 30 '22 19:09

ezakto