在鼠标移开 jquery 区块后,如何停止执行尚未执行的函数?

2025-03-22 21:38:10
推荐回答(2个)
回答1:

详见stop()方法

回答2:

需借助setTimeout();


Demo:

var timer;
$('#elem').on('mouseenter',function() {
    timer = setTimeout(function(){
        //your bussiness
    },200 );
});
$('#elem').on('mouseleave',function() {
    clearTimeout( timer );
    //your bussiness
});