3

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

目前它触发得太早了,我宁愿等待 500 毫秒,然后再评估鼠标。我在下面使用的代码示例。

$('.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 方法可以做到这一点,还是我必须自己做?

4

3 回答 3

9

将内部的逻辑拆分mouseout为另一个函数。mouseout甚至用setTimeout("myMouseOut", 500). 如果用户移动到新元素,您可以将mouseover事件与 a结合起来重置计时器。clearTimeout()

于 2010-02-15T16:43:33.447 回答
5

你总是可以将你的逻辑包装在一个setTimeout()函数中。

mouseout: function() {
  setTimeout(function(){
    $c('hide!');
    hideUnderConstruction();
  }, 500);
}
于 2010-02-15T16:41:19.287 回答
3

您可以查看hoverIntent 插件让您定义一些有助于 mouseenter/out 交互的变量

于 2010-02-15T16:52:42.917 回答