Reputation: 11
var slideContainer = ('#slider');
var width = 720;
function slide () {
if ( parseInt( $slideContainer.css('marginLeft') ) >= -2160 ) {
$slideContainer.animate({'margin-left': '-='+width},200);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class='button' onclick='slide()'></a>
I have this simple function, the problem is when I click multiple clicks on the button with animation speed more than 150 it take the slider container more to the left more than -2160 the limit in my if condition .
Upvotes: 1
Views: 1320
Reputation: 98
You can achieve this in either ways-
var events = $._data(sliderContainer[0], 'events');
handler = events.click;
events.click = null;
slideContainer.animate({'margin-left': '-='+width},{duration: 200, complete:function(){evends.click = handler }});
Hope this helps..
Upvotes: 0
Reputation: 21
var slideContainer = ('#slider');
var width = 720;
var clicked = false;
function slide () {
if ( clicked ) return;
clicked = true;
if (parseInt( $slideContainer.css('marginLeft') ) >= -2160 ) {
$slideContainer.animate({'margin-left': '-='+width},200,"linear",()=>{
clicked=false;});
}
}
<a class='button' onclick='slide()'></a>
Upvotes: 1