I'm trying make a button unusable while animate running. I coded a simple scroll with the button but if a user clicks the button repeatedly, the animation doesn't stop so scrolling will repeat over and over. I tried using unbind
on the element when clicked and bind
again when the animtation had finished but it doesn't appear to work. Here is my code:
$(".go_up").bind('click',function(){
var $this = $(this);
var $content_page = $this.siblings('.componentin').children('.item-page');
var $content_math = $content_page.height();
var $content_height = ($content_math)*(-1);
var $content_margin = $content_page.css("margin-top");
if (($content_margin) <= '0') {
$this.unbind("click");
$content_page.animate({ marginTop: "+=100px" }, "slow", function(){
$this.bind("click");
});
}
});
And here is the example: www.erincfirtina.com/bar/
[FIXED]
$(".go_up").bind('click',function(){ var $this = $(this); var $content_page = $this.siblings('.componentin').children('.item-page'); var $content_math = $content_page.height(); var $content_height = ($content_math)*(-1); var $content_margin = $content_page.css("margin-top"); if ((($content_margin) <= '0') && (!$content_page.is(":animated"))){ $content_page.animate({marginTop: "+=100px"}, "slow"); } });
added .is(":animated")
and works smoothly