主导航在页面加载时采用悬停样式
我正在制作一个水平导航菜单。我对这个菜单还有一个问题。当用户导航到页面时,我希望主 li 保持悬停。现在,li 不再保持悬停状态,而是恢复为默认状态。我是否需要给身体上一堂课才能使其发挥作用,还是有其他方法?代码片段可以在这里找到: http://jsfiddle.net/SeasonEnds/LSmfN/
理想情况下, “阅读”选项卡应在加载页面时采用悬停样式,但当用户将鼠标悬停在其他主要导航链接上时消失。
I have a horizontal nav menu that I am working on. I have one issue left with this menu. When the user navigates to a page, I would like the main li to remain hovered. Right now, the li does not remain in a hovered state and simply reverts to default. Do I need to give the body a class to make this work or is there another way? The code snippet can be found here: http://jsfiddle.net/SeasonEnds/LSmfN/
Ideally, the Read tab should take on the hover styles upon on loading the page, but go away as the user hovers over the other main nav links.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当用户将鼠标悬停在另一个顶级链接上时,活动元素上的突出显示不应该真正消失,因为这不利于可用性 - 如果用户不单击链接,那么他们就失去了他们在哪里的视觉线索在您的网站上。
我稍微修改了 css:
我还添加了一些 jQuery,以在将鼠标悬停在子项上时保持活动顶级链接的颜色:
更新了小提琴:
http://jsfiddle.net/LSmfN/14/
The highlight on the active element shouldn't really disappear when the user hovers on another top-level link as this is bad for usability - if the user doesn't click on a link then they've lost the visual clue as to where they are on your site.
I've amended the css slightly:
I've also added a bit of jQuery to keep the colour of the active top-level link as you hover over the children:
Updated fiddle:
http://jsfiddle.net/LSmfN/14/
如果服务器没有设置活动菜单元素,或者没有 JS 指示活动元素,菜单就无法知道它位于哪个页面。
您可以执行以下操作 - 在“此处”添加一个类来指示当前位置:
使用 js 检测当前页面:
There's no way for the menu to know which page it's on without either the server setting the active menu element, or JS indicating the active element.
Here's what you can do - add a class "here" to indicate the current position:
Detect the current page using js: