我试图让一个按钮无法使用,同时动画运行。我用按钮编码了一个简单的滚动条,但如果用户反复点击按钮,动画不会停止,因此滚动会一遍又一遍地重复。点击时,我尝试在元素上使用unbind
,并且在动画完成后再次尝试使用bind
,但它看起来不起作用。这里是我的代码:jquery解除绑定按钮,而.animate()正在运行
$(".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");
});
}
});
这里是例子:www.erincfirtina.com/bar/
[固定]
$(".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"); } });
添加.is(":animated")
和工程进展顺利
绑定将采取两个参数对吗? – sathis
可能是duplaicate http://stackoverflow.com/questions/2593195/how-do-i-rebind-the-click-event-after-unbindclick – DoubleYo
谢谢。有用!我在if子句中添加了“.is(”:animated“)”,并修复了它。 –