简体   繁体   English

修复了Navbar破坏展开菜单的问题

[英]Fixed Navbar broke unrolling menu

I am helping on this website: www.noyoco.com. 我正在以下网站上提供帮助:www.noyoco.com。 I recently added a script to fix the nav bar on top when user scrolls. 我最近添加了一个脚本,用于在用户滚动时将导航栏固定在顶部。

    <script type="text/javascript">
  $(document).ready(function() {
    var s = $("#main-nav");
    var pos = s.position();     
    $(window).scroll(function() {
        var windowpos = $(window).scrollTop();
        if (windowpos >= pos.top) {
            s.addClass("stick");
        } else {
            s.removeClass("stick"); 
        }
    });
});
</script>

But I can't figure out why unrolling menu is broken. 但是我不知道为什么展开菜单损坏了。

Working properly when on top (script is off), broken when script is on (if you have scroll) 在顶部时正常工作(关闭脚本),在打开脚本时断开(如果滚动)

Can someone help with that? 有人可以帮忙吗? Thanks! 谢谢!

It's because of the fact that the second menu is not in absolute position of the nav container. 这是因为第二个菜单不在导航容器的绝对位置。 It's only in display: block; 它仅在display: block; and display: none; display: none; when you toggle it with the main menu. 当您使用主菜单切换时。

To fix that, you can add a relative position on the parent container like this : 为了解决这个问题,您可以像这样在父容器上添加相对位置:

.multi-level-nav {
  position: relative;
}

And an absolute position to the menu on the submenu : 以及子菜单上菜单的绝对位置:

.tier-2 { 
  position: absolute; 
  left: 0; 
  right: 0;
  z-index: 2; /* to be above the slideshow */
}

Hope that helps. 希望能有所帮助。

EDIT 编辑

It's also because of this selector, you have to change it because of the change of the structure when it becomes fixed : 也由于这个选择器,您必须更改它,因为它在fixed改变结构:

.nav-row ul ul {
    display: none;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM