Jquery - 延迟mouseout事件 [英] Jquery - Delay mouseout event

查看:156
本文介绍了Jquery - 延迟mouseout事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让jquery在mouseout事件被触发之前等待一段时间?

Is there a way to make jquery wait a certain about amount of time before mouseout event is fired?

现在发射得太早了我想我喜欢在评估鼠标之前等待500ms。我在下面使用的代码示例。

It is firing too early at the moment and I'd prefer to wait 500ms before it evaluates the mouse out. An example of the code I'm using below.

$('.under-construction',this).bind({
    mousemove: function(e) {
        setToolTipPosition(this,e);
        css({'cursor' : 'crosshair' });
    },
    mouseover: function() {
        $c('show!');
        showUnderConstruction();
    },
    mouseout: function() {
        $c('hide!');
        hideUnderConstruction();
    },
    click: function() {
        return false;
    }
});

有没有jquery方法可以做到这一点,还是我必须自己做?

Is there a jquery way to do this or will I have to do it myself?

推荐答案

mouseout 中的逻辑拆分为另一个函数。在 mouseout 中甚至用 setTimeout(myMouseOut,500)调用此函数。并且您可以将 mouseover 事件与 clearTimeout()结合使用,以便在用户进入新元素时重置计时器。

Split the logic inside the mouseout into another function. in the mouseout even call this function with a setTimeout("myMouseOut", 500). And you can combine the mouseover event with a clearTimeout() to reset the timer if the user moves into a new element.

这篇关于Jquery - 延迟mouseout事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆