Drupal 菜单上的悬停问题
我有一个菜单,当用户将鼠标悬停在菜单上时,会出现子菜单。只是,当您未将鼠标悬停在文本上时,子菜单会消失。
让我尝试用图像来表达清楚。
悬停文本时(应该如何):
导致此结果
将鼠标悬停在文本附近的区域时:
导致此结果
更复杂的是,它只发生在 Safari en Chrome 中(我猜是 webkit 引擎)而且它并不总是这样做:)
我猜这是一个CSS问题,但有人知道在哪里看吗?
(哦,这是一个 Drupal 网站,所以我不知道它是否能正常运行...)
更新
HTML 如下所示:
I have a menu and when the user hovers the menu, the submenu appears. Only, the submenu disappears when you're not hovering the text.
Let me try to make it clear using images.
When hovering the text (how it should be):
leads to this
When hovering the area near the text:
leads to this
And to make it even more complicate, it only happens in Safari en Chrome (the webkit engine I guess) and it doesn't do this all the time :)
I'm guessing it's a css problem, but anyone know where to look?
(Oh, and it's a Drupal website, so I don't know it this plays along...)
UPDATE
This is how the HTML looks like:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一些模块可以为您执行此操作,例如 Nice Menus。
子菜单可能不是 DOM 中父菜单的子菜单。可能是这样的:
因此,当您将鼠标悬停在子菜单上时,会在父菜单上触发 mouseLeave/mouseOut 。
您可以通过多种方式解决这个问题。一种是重构 HTML,使子菜单位于父菜单中:
或者在 JavaScript 中检测/保存悬停项目状态。为此,一种可能的方法是使用 jQuery 数据对象保存或添加一个类(例如“on”)到您悬停的菜单,并使用同级/子选择器来检测您是否位于子菜单中。如果您不在父菜单或子菜单中,请删除“on”类。
有很多方法可以做到这一点,无论是在 JavaScript/HTML/CSS 中还是使用 Drupal 模块。如果您仍然感到困惑,请显示一些代码。
There are modules that can do this for you, such as Nice Menus.
The submenu is probably not a child of the parent menu in the DOM. It's probably something like this:
So when you hover over the submenu, mouseLeave/mouseOut is triggered on the parent.
You can solve this in multiple ways. One is to restructure your HTML such that the submenu is in the parent:
or to detect/save the hovered item state in JavaScript. To do that, one possible way is to save the using either a jQuery data object or add a class (e.g. "on") to the menu you hover over and use sibling/child selectors to detect if you're in a submenu. If you're not in the parent or a submenu, remove the "on" class.
There's many ways to do this, both in JavaScript/HTML/CSS and using Drupal Modules. Show some code if you're still confused.