2013-03-14 61 views
0

您好,我试图在动画完成后解除绑定事件,并且不想在该容器上触发该事件。我的方法容器上的jquery动画,然后解除绑定事件

$('#container').on('mouseover.grow', function(){ 
    $(this).parents('.secondary').animate({height:'360'},1000); 
}).off('mouseover.grow'); 

但是,这种方法似乎并不像工作。任何指针,我在这里失踪将不胜感激...

回答

2

链接.off()方法,因为你已经完成将导致它立即发射。

你要调用它的complete回调.animate()方法(即等到生命的结束):

$('#container').on('mouseover.grow', function(){ 
    var $this = $(this); 

    $this.parents('.secondary').animate({height:'360'},1000, function() { 
     $this.off('mouseover.grow'); 
    }); 
}); 

另外请注意,我们分配var $this = $(this);this范围将是在回调函数中不同。

+0

谢谢!好像我在错误的地方取消了。 – paul 2013-03-14 23:05:08