2012-03-04 60 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