【问题标题】:How to use the setTimeout(function () to delay the drop down menu in JS?JS中如何使用setTimeout(function()延迟下拉菜单?
【发布时间】:2014-05-01 18:35:58
【问题描述】:

如何使用 setTimeout(function () 来延迟下拉或 _mouseOverHandler 与 _mouseOutHandler 在这里延迟的方式相同。如果您看到以下菜单,关闭时会有 0.250 秒的延迟。我想要相同的延迟打开或下拉菜单。

测试页面: http://terrillthompson.com/tests/menus/accessible-mega-menu/test.html

JS 代码: http://terrillthompson.com/tests/menus/accessible-mega-menu/js/jquery-accessibleMegaMenu.js

提前致谢, 瑞克

【问题讨论】:

  • 请把相关的代码和标记贴在这里,以供以后的SO'er使用。
  • 你想更新库还是在你自己的js中做?
  • 嗨 @jayaguilar 我想通过修改 jquery-accessibleMegaMenu.js 从我自己的 js 中做到这一点
  • @JayBlanchard 我试过了,但是代码太长了,但这里是它的链接terrillthompson.com/tests/menus/accessible-mega-menu/js/…干杯,R
  • 这个库的创建方式让你更容易更新js本身,如果你想让我告诉你怎么做,我会把它作为答案提交

标签: javascript jquery drop-down-menu settimeout


【解决方案1】:

@Ricardo79 2 件事情你需要它以你想要的方式工作:

1.更新 _mouseOverHandler 为:

_mouseOverHandler = function (event) { var that= this; clearTimeout(this.mouseTimeoutID); $(event.target) .addClass(this.settings.hoverClass); that.mouseTimeoutID = setTimeout(function(){ _togglePanel.call(that, event); },250); if ($(event.target).is(':tabbable')) { $('html').on('keydown.accessible-megamenu', _keyDownHandler.bind(event.target)); } };.

2. 在 var that = this 之后向 _mouseOutHandler 添加一个 clearTimeOut clearTimeout(this.mouseTimeoutID);

这是一个工作示例http://jsfiddle.net/LfD9v/1/

【讨论】:

  • 每当您从外部资源复制/粘贴代码时,请注明该代码的作者。
  • @jayaguilar 你摇滚!非常感谢!工作完美..我只需要做一些 css 工作,我正在滚动。再次感谢!
  • @RPM 不确定你的意思,但在 jsfiddle 上我留下了所有作者的功劳,请让我知道该怎么做,我很乐意这样做。
  • @Ricardo79 太棒了,如果你不介意你能接受答案吗?
猜你喜欢
  • 2010-12-10
  • 1970-01-01
  • 2014-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-09
  • 2012-01-25
  • 2016-04-02
相关资源
最近更新 更多