jquery click: how to check if the button is clicked or not clicked?
How can I not to run a code if a button is clicked? For instance, this timer in开发者_如何学Python my plugin will be triggered if the previous button is not clicked, but I don't want to run this timer code when the button is clicked.
$.fn.run_slide.timer_each = setTimeout(function() {
$.fn.run_slide.loop_slide(object);
},o.timerEach);
This timer code is inside this chunk of code,
next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, o.timerTransition, function(){
current.animate({opacity: 0.0}, o.timerTransition).removeClass('active last-active');
$.fn.run_slide.timer_each = setTimeout(function() {
$.fn.run_slide.loop_slide(object);
},o.timerEach);
});
I was thinking to do something like this but I think it is not the right method,
if(!button_previous.click)
{
$.fn.run_slide.timer_each = setTimeout(function() {
$.fn.run_slide.loop_slide(object);
},o.timerEach);
}
Any ideas?
Thanks.
Edit:
found the problem in my code and this is my solution:
// Check if the next button or previous button is not clicked then fade the current slide.
if(!button_previous.click) current.animate({opacity: 0.0}, o.timerTransition).removeClass('active last-active');
You can stop a timeout from being executed the next time by using clearTimeout(), passing the setTimeout() handler as a parameter.
Should be something like this
clearTimeout( $.fn.run_slide.timer_each );
But I'm not sure if you sticked the setTimeout handler in a good position.
Use clearTimeout, as demonstrated in this fiddle.
精彩评论