javascript - 如何在事件执行完毕后立刻停止事件
ringa_lee
ringa_lee 2017-06-14 10:54:31
0
5
792

我有一个鼠标移入移出显示隐藏的事件,但是鼠标如果多次滑过就会执行多次,如何在鼠标移出事件执行完毕后立刻停止事件?

$(".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

全部回复(5)
洪涛

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

大家讲道理

雷雷

黄舟

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

参考

漂亮男人

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

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

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

雷雷

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

雷雷

});

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!