2013-03-14 58 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