简体   繁体   English

固定位置导航栏不起作用

[英]Fixed position navigation bar not working

I'm using an parallax jquery plugin 我正在使用视差jQuery插件

What parallax.js will do is create a fixed-position element for each parallax image at the start of the document's body. parallax.js要做的是在文档正文的开头为每个视差图像创建一个固定位置的元素。 This mirror element will sit behind the other elements and match the position and dimensions of it's target object. 该镜像元素将位于其他元素后面,并与其目标对象的位置和尺寸匹配。

I've added this markup for the navigation: 我为导航添加了此标记:

<nav class="nav-inner" role="navigation">

    <a class="navbar-brand" href="#"><img src="img/logo.png"></a>

</nav>

and this CSS : 和这个CSS:

.nav-inner {
  position:fixed;
  top:0;
  left:0;
  z-index:500;
 }

The problem is that when I scroll down the navigation doesn't stay fixed on top of the page as I expected. 问题是,当我向下滚动时,导航并不会像预期的那样固定在页面顶部。

Here is a jsbin to see it what happens. 这是一个jsbin ,看看会发生什么。

Any suggestions on how can I make that navigation bar to stay fixed ? 关于如何使导航栏保持固定的任何建议?

Just set z-index:0 for all your parallax-mirror elements 只需为所有parallax-mirror元素设置z-index:0

.parallax-mirror {z-index:0 !important;}

Or change the attribute directly in elements style attribute because it has z-index:-100 或直接更改元素样式属性中的属性,因为它具有z-index:-100

I usually make my fixed navigation bars differently. 我通常使固定的导航栏有所不同。 Here is my code. 这是我的代码。 It works for me: 这个对我有用:

CSS: CSS:

#navBar
{
    position:fixed;
    top:0;
    left:0;
    right:0;
    color:#000;
    background-color:#fff;
    padding-left:2em;
    opacity:.9;
    z-index:100;
}

#navBar > a (however you reference your child elements)
{
margin:-4px;
}

HTML: HTML:

<div id="navBar"><a href="">anywhere</a><a href="">anywhere</a></div>

If this doesn't work let me know and I'll take a look at my answer. 如果这不起作用,请告诉我,我将看一看我的答案。

由于您已经使用jQuery,因此可以在此处找到jQuery插件: http : //www.jqueryrain.com/demo/jquery-fixed-header/

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

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