【问题标题】:Jquery - Delay mouseout eventJquery - 延迟 mouseout 事件
【发布时间】:2011-01-17 01:35:58
【问题描述】:

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

目前它触发得太早了,我宁愿等待 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 方法可以做到这一点,还是我必须自己做?

【问题讨论】:

  • showUnderConstruction().delay(500); hideUnderConstruction().delay(500);

标签: javascript html jquery jquery-events mouseout


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    您始终可以将您的逻辑包装在 setTimeout() 函数中。

    mouseout: function() {
      setTimeout(function(){
        $c('hide!');
        hideUnderConstruction();
      }, 500);
    }
    

    【讨论】:

      【解决方案3】:

      您可以查看hoverIntent plugin 让您定义一些有助于鼠标输入/输出交互的变量

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-12-19
        • 2017-01-31
        • 2015-01-17
        • 2012-07-11
        • 2010-09-30
        • 1970-01-01
        • 2013-12-31
        • 1970-01-01
        相关资源
        最近更新 更多