Может ли e.preventDefault () быть отменен? - PullRequest
6 голосов
/ 04 марта 2012

Я ищу способ .preventDefault () сделать переход, а затем разрешить поведение по умолчанию

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

})

Ответы [ 3 ]

6 голосов
/ 04 марта 2012
$('.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");
    });
});
1 голос
/ 04 марта 2012

при условии, что вы пытаетесь перейти по ссылке после завершения анимации:

$('.withTrans').click(function(e){
    $(this).animate('opacity','0',300,function(){
          window.location= this.href;
    });
    return false;
});
0 голосов
/ 06 ноября 2014
$('.withTrans').each(function(e){
    $(this).unbind();
}
...