2012-03-04 57 views
6

我正在寻找一种方式来.preventDefault()做一个过渡,然后允许默认行为是否可以颠倒e.preventDefault()?

$('.withTrans').click(function(e){ 
    e.preventDeault(); 
    $(this).animate('opacity','0',300,function(){ 
      e.resumeDefault();  // does something like this exist? 
    }); 

}) 
+1

看到这个:http://stackoverflow.com/questions/1238477/suspend-default-event-in-jquery – 2012-03-04 15:29:52

+1

没有内置的功能。当动画结束时,事件处理也可能已经完成。 – 2012-03-04 15:31:18

回答

6
$('.withTrans').click(function(event) { 
    if ($(this).data("prevented") === true) { 
     $(this).data("prevented", false); 
     return; 
    } 
    event.preventDefault(); 
    $(this).animate('opacity', '0', 300, function() { 
      $(this).data("prevented", true).trigger("click"); 
    }); 
}); 
+0

这不是触发...触发器(“点击”)来重温相同的点击事件..任何建议? – 2016-01-27 00:39:04

1

假设你正试图遵循链接动画完成后:

$('.withTrans').click(function(e){ 
    $(this).animate('opacity','0',300,function(){ 
      window.location= this.href; 
    }); 
    return false; 
}); 
+0

不,我们不能... ... – 2012-03-05 08:58:42

0
$('.withTrans').each(function(e){ 
    $(this).unbind(); 
} 
+0

请描述,这个答案如何解决问题 – Hamad 2014-11-06 05:09:17