gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 15:45:47 26 4
gpt4 key购买 nike

用于导航菜单的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com