javascript – So stoppen Sie ein Ereignis sofort, nachdem die Ausführung abgeschlossen ist
ringa_lee
ringa_lee 2017-06-14 10:54:31
0
5
793

Ich habe ein Ereignis, das angezeigt und ausgeblendet wird, wenn die Maus mehrmals darüber bewegt wird. Wie kann ich das Ereignis sofort nach der Ausführung des Maus-Aus-Ereignisses stoppen?

$(".target").on('mouseenter',function() {
    $(this).children('.p1').show(function(){
        $(this).addClass('animated fadeInLeft');
        $(this).removeClass('animated fadeInLeft');
    })
});
$(".target").on('mouseleave',function() {
    $(this).children('.p1').hide(function(){
        $(this).addClass('animated fadeOutLeft');
        $(this).removeClass('animated fadeOutLeft');
    })
});
ringa_lee
ringa_lee

ringa_lee

Antworte allen(5)
洪涛

题主如果要用只执行一次的方法,用.one()就行,但是一般jQuery的动画特效一定要考虑动画队列的问题,建议在执行动画之前加上.stop()方法来停止“进入动画队列但是未完全执行完”的动画

大家讲道理
$(".target").on('mouseenter',function() {
    $(this).children('.p1').show(function(){
        $(this).addClass('animated fadeInLeft');
        $(this).removeClass('animated fadeInLeft');
    })
});
$(".target").on('mouseleave',function() {
    $(this).children('.p1').hide(function(){
        $(this).addClass('animated fadeOutLeft');
        $(this).removeClass('animated fadeOutLeft');
    })
    $(this).unbind();    //加一句这个取消当前dom的所有绑定事件
});
黄舟

on后边加个e,你用.one()这个API它就是执行一次自动删除了。

参考

漂亮男人

你是想说马上中止动画吧,用 stop()

$(this).children('.p1').stop(true, true)
学习ing

$(".target").off('mouseenter').on('mouseenter',function() {

$(this).children('.p1').show(function(){
    $(this).addClass('animated fadeInLeft');
    $(this).removeClass('animated fadeInLeft');
})

});
$(".target").off('mouseenter').on('mouseleave',function() {

$(this).children('.p1').hide(function(){
    $(this).addClass('animated fadeOutLeft');
    $(this).removeClass('animated fadeOutLeft');
})

});

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!