javascript - 导航菜单不会停留在屏幕前面

标签 javascript html css

用于导航菜单的 Java 脚本:
//

  $(function() {
    // Stick the #nav to the top of the window
    var nav = $('#nav');
    var navHomeY = nav.offset().top;
    var isFixed = false;
    var $w = $(window);

   $w.scroll(function() {
    var scrollTop = $w.scrollTop();
    var shouldBeFixed = scrollTop > navHomeY;
    if (shouldBeFixed && !isFixed) {
        nav.css({
            position: 'fixed',
            top: 0,
            left: nav.offset().left,
            width: nav.width()
        });
        isFixed = true;
    }
    else if (!shouldBeFixed && isFixed)
    {
        nav.css({
            position: 'static'
        });
        isFixed = false;
    }
    });

   });

//]]>  

HTML代码:

<div> <div class="pic"> <img  class="image" src="logo.jpg"/> </div> </div>  

类的 CSS:

.image{
width: 1000px;
height:800px;

opacity: 0.3;
filter: alpha(opacity=30); /* For IE8 and earlier */
 -webkit-transition: all 1s ease;
 -moz-transition: all 1s ease;
   -o-transition: all 1s ease;
  -ms-transition: all 1s ease;
      transition: all 1s ease;
       }
.image:hover {
  width: 1100px;
  height: 900px;
  opacity: 0.9;
filter: alpha(opacity=100); /* For IE8 and earlier */
}




.pic {
 border: 10px solid #fff;  

 height: 800px;
 width: 1000px;
 margin: 20px;
 overflow: hidden;

 -webkit-box-shadow: 5px 5px 5px #111;
      box-shadow: 5px 5px 5px #111;  

}

图像是透明的,悬停时会放大并移除透明度。导航菜单是enter image description here粘在顶部并在滚动时移动(使用 JavaScript 代码)。图像位于导航菜单的正下方,当鼠标悬停在图像上时,导航菜单链接变得不可点击。有没有办法将菜单固定在前面?我试过 position: fixed;但它不起作用。

Here is what exactly I mean, in first picture links work normally but in 2. they hide behind picture

最佳答案

z-index 属性添加到您的 #wrap

#wrap {
  z-index: 1;
  ...
}

已更新 JSFiddle

关于javascript - 导航菜单不会停留在屏幕前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42748408/

相关文章:

java - 临时编码的工作流程

html - 带有点击事件的非javascript多行控件

css - Boxshadow 仅在侧面

javascript - 在 JavaScript 事件中更改图像大小

html - 如何将按钮与文本(标签)放在同一行

javascript - 返回包含每个对象的命名属性的数组

javascript - React 状态已设置,但在渲染时看起来它是空的

javascript - 如何停止广度优先搜索递归函数

javascript - jQuery Toggle 第二次无法正常工作

html - Zen Code 为数独解算器创建 html 布局