jQuery - 取消绑定或重新绑定hoverIntent()?
我有一个菜单栏,在上一行显示一组类别。
其中一个类别具有一组子类别。
我有一个悬停意图设置,以便它会在子菜单中向下滑动,并在鼠标离开时向上滑动。
但是,如果我正在查看此类别中的页面,我希望子菜单可见,并突出显示活动类别。我还想确保当通过鼠标与子菜单交互时,一旦鼠标离开,它不会再次向上滑动。
我尝试在此页面中的元素上重新声明hoverIntent函数,但它不起作用,它仍然使用以前的绑定。有没有办法解除之前的hoverIntent的绑定并确保它使用新的?
I have a menu bar that displays a set of categories in an upper row.
One of the categories has a set of sub-categories.
I have a hoverIntent setup so that it will slideDown the submenu, and slideUp when the mouse leaves.
However, if I am viewing a page in this category, I would like the submenu to be visible with the active category highlighted. I would also like to make sure that when the submenu is interacted with via the mouse, it does not slideUp again once the mouse leaves.
I have tried redeclaring the hoverIntent function on the element in this page but it does not work, it is still using the previous binding. Is there any way to unbind the previous hoverIntent and make sure it uses the new one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
要绑定和取消绑定
hoverIntent
你应该这样做:to bind and unbind the
hoverIntent
you should do:我认为这是一个更完整的答案。它执行以下操作:
代码的本机部分:
I think this is a more complete answer. It does the following:
Code:
来自 jQuery 文档:“在最简单的情况下,没有参数,.unbind() 会删除附加到元素的所有处理程序”
From jQuery docs: "In the simplest case, with no arguments, .unbind() removes all handlers attached to the elements"
我用过:
I used: