can e.preventDefault() be reversed?

房东的猫 提交于 2019-12-19 18:48:30

问题


i am looking for a way to .preventDefault() to make a transition and then allow the default behavior

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

})

回答1:


$('.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");
    });
});



回答2:


assuming you are trying to follow a link after the animation is complete:

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



回答3:


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


来源:https://stackoverflow.com/questions/9556107/can-e-preventdefault-be-reversed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!