jquery addClass - 等待、延迟、速度、超时或其他
这个问题已经被发布了好几次,是如何延迟 addClass 的。
我得到了这个:
$("#menu ul li").hover(function(){
$(this).addClass("hover");
},function(){
$(this).removeClass("hover");
})
并且想要类似的东西,但是在 500msek 左右之后添加类。到目前为止最好的答案是使用 settimeout。也许我只需要一个工作示例: 如何使用 jQuery 等待 5 秒?
hooverIntent 将无法工作它必须是一个addClass。
Br。安德斯
更新:四个很好的答案!谢谢。我不知道为什么我认为hoverIntent不起作用,它可以如答案中所示使用。实际上,所有答案都可以使用,各有利弊。即使必须包含另一个插件,我也会使用hoverIntent。 hoverIntent 的优点是可以设置灵敏度,因此不仅可以设置 addClass 的延迟,而且当鼠标仍然位于该区域上方时(或者如果喜欢灵敏度,则不会那么静止),它将首先开始计数
The question has been posted several times and is how to delay an addClass.
I got this:
$("#menu ul li").hover(function(){
$(this).addClass("hover");
},function(){
$(this).removeClass("hover");
})
And want something similar but where the class is added after 500msek or so. Best answer so far is this one using settimeout. Maybe I just need a working example:
How to wait 5 seconds with jQuery?
The hooverIntent will not work since it has to be an addClass.
Br. Anders
UPDATE: Four great answers! Thanks. I do not know why I did not think the hoverIntent would work, it can be used as seen in the answers. Actually all answers can be used each with pros and cons. I will go with the hoverIntent even though another plugin must be included. The pro for the hoverIntent is that a sensibilty can be set so not only a delay for the addClass can be set but it will first start counting when the mouse is positioned still obove the area (or not so still if sensitivety is lovered)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这就是您要找的吗?
Is that what youre looking for?
我不明白为什么 hoverIntent 不起作用:
I don't see why hoverIntent won't work:
像这样的东西
Something like this
抛开 setTimeout 和悬停意图不谈(尽管它们是最明显的方法),我们不能为此使用空动画回调吗?
Leaving setTimeout and hoverintent aside (although they are the most obvious ways to go), couldn't we use a null animation callback for this?