为鼠标悬停时的 jquery 事件添加延迟
我正在尝试为孩子的鼠标悬停事件添加一个简单的延迟,但遇到了困难。 (仍在学习!)
这使我能够在延迟后显示弹出窗口,但同时显示所有弹出窗口:
onmouseover='setTimeout(function() { $(\".skinnyPopup\").show(); }, 600)'
这可以仅显示我想要的弹出窗口,没有延迟:
onmouseover='$(this).children(\".skinnyPopup\").show()'
但组合不会:
onmouseover='setTimeout(function() { $(this).children(\".skinnyPopup\").show(); }, 600)'
任何帮助将不胜感激。谢谢!
I am trying to add a simple delay to a mouseover event of a child and having difficulties. (Still learning!)
This enables me to show the popup after a delay, but shows all of them simultaneously:
onmouseover='setTimeout(function() { $(\".skinnyPopup\").show(); }, 600)'
and this works to show only the popup I want with no delay:
onmouseover='$(this).children(\".skinnyPopup\").show()'
but the combination does not:
onmouseover='setTimeout(function() { $(this).children(\".skinnyPopup\").show(); }, 600)'
Any help would be appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在执行时定义
this
是什么,类似这样的东西可以工作:或者只使用
.delay()
,如下所示:以上两个都是快速修复,我建议您远离内联处理程序并查看 不引人注目方法(请参阅此答案,作者:Russ Cam 出于一些重要原因),例如:
You need to define what
this
is when it executes, something like this would work:Or just use
.delay()
, like this:Both of the above are quick fixes, I suggest you move away from inline handlers and check out an unobtrusive method (see this answer by Russ Cam for some great reasons), for example:
这是因为
this
绑定到全局上下文,而不是元素。请使用类似以下内容:如果您坚持使用内联事件处理程序,则以下内容也应该有效:
It's because
this
is bound to the global context, not the element. Use something like the following instead:If you're adamant about inline event handlers, the following should also work: