我在使用转换后遇到固定标头的问题,它会在所有浏览器中跳转,特别是在Mozilla中。我添加了jquery滚动函数并添加了类fixed-hd来实现这一点。我尝试从标题中删除转换并且它可以正常工作,但是当我将转换回到代码中时,它开始跳转鼠标上下滚动。任何人都知道问题在哪里,提前谢谢
Jquery代码:
$(document).ready(function() {
$(window).scroll(function() {
if ($(window).scrollTop() > 50) {
$('.header').addClass('fixed-hd');
}
else
{
$('.header').removeClass('fixed-hd');
}
});
});
.header-section {
width: 100%;
height: 667px;
background: url(../images/bg_img.png) repeat-x;
}
.header {
width: 100%;
position: relative;
top: 40px;
-webkit-transition: all .7s ease-in-out;
-moz-transition: all .7s ease-in-out;
-ms-transition: all .7s ease-in-out;
-o-transition: all .7s ease-in-out;
transition: all .7s ease-in-out;
}
.hd-fxd {
width: 1280px;
height: 60px;
margin: 0 auto;
}
.logo {
width: 640px;
height: 60px;
float: left;
position: relative;
}
.logo a {
position: absolute;
top: 17px;
left: 20px;
color: #fff;
font-weight: bold;
font-size: 1.6em;
}
.nav-menu {
width: 640px;
height: 60px;
float: left;
}
.nav-menu ul {
width: 640px;
height: 60px;
background: #53706f;
text-align: center;
}
.nav-menu ul li {
display: inline-block;
height: 60px;
line-height: 60px;
}
.nav-menu ul li:hover {
background: #587373;
}
.nav-menu ul li a {
width: 120px;
font-size: 17px;
color: #fff;
display: block;
}
.fixed-hd {
position: fixed;
top: 0;
left: 0;
right: 0;
width: 100%;
margin: 0 auto;
height: 60px;
background: #53706f;
}
.section {
height: 1000px;
}

<div class="header-section">
<div class="header-wrapper">
<div class="header">
<div class="hd-fxd">
<div class="logo">
<a href="#">Extreme</a>
</div><!-- end logo !-->
<div class="nav-menu">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Portfolio</a></li>
<li><a href="#">Contact</a></li>
</ul><!-- end ul !-->
</div><!-- end nav-menu !-->
</div><!-- end hd-fxd !-->
</div><!-- end header !-->
</div><!-- end header-wrapper !-->
</div><!-- end header-section !-->
<div class="section">
</div>
&#13;
答案 0 :(得分:2)
试试这个css
body{
padding: 0;
margin: 0;
}
.header-section {
width: 100%;
height: 667px;
background: url(../images/bg_img.png) repeat-x;
}
.header {
width: 100%;
position: relative;
top: 40px;
-webkit-transition: all .7s ease-in-out;
-moz-transition: all .7s ease-in-out;
-ms-transition: all .7s ease-in-out;
-o-transition: all .7s ease-in-out;
transition: all .7s ease-in-out;
position: fixed;
top: 0;
left: 0;
right: 0;
}
.hd-fxd {
width: 1280px;
height: 60px;
margin: 0 auto;
}
.logo {
width: 640px;
height: 60px;
float: left;
position: relative;
}
.logo a {
position: absolute;
top: 17px;
left: 20px;
color: #fff;
font-weight: bold;
font-size: 1.6em;
}
.nav-menu {
width: 640px;
height: 60px;
float: left;
}
.nav-menu ul {
width: 640px;
height: 60px;
background: #53706f;
text-align: center;
margin: 0;
padding: 0;
}
.nav-menu ul li {
display: inline-block;
height: 60px;
line-height: 60px;
}
.nav-menu ul li:hover {
background: #587373;
}
.nav-menu ul li a {
width: 120px;
font-size: 17px;
color: #fff;
display: block;
}
.fixed-hd {
position: fixed;
top: 0;
left: 0;
right: 0;
width: 100%;
margin: 0 auto;
height: 60px;
background: #53706f;
}
.section {
height: 1000px;
}
答案 1 :(得分:1)
<强> DEMO 强>
将标头从position: relative;
更改为position: fixed;
。
这使得标题转换正确。