我正在为一个朋友建立一个网站,我刚刚实现了一个固定的标题。
http://scsports.comeze.com/blog.php
问题是当您滚动标题时向右移动大约 7px。我不知道为什么,我尝试过的一切都不起作用。任何想法将不胜感激!
HTML+JS:
<div class="navbar">
<div class="navbar-inner">
<a class="brand" href="#"><img src="images/logo2.png" class="logo" alt="header logo"></a>
<?php include 'socialbtn.php';?>
<div class="test">
<ul class="nav">
<!--<li class="active">-->
<li><a id="index_link" href="index.php">Home</a></li>
<li><a id="therapist_link" href="therapist_profile.php">Therapist Profile</a></li>
<li><a href="services.php">Services & Prices</a></li>
<li><a href="testimonials.php">Testimonials</a></li>
<li><a href="contact.php">Contact Me</a></li>
<li><a href="blog.php">Blog</a></li>
<li><a href="raceready.php">Race Ready?</a></li>
<li><a href="treatment.php">What We Treat</a></li>
<li><a href="expect.php">What To Expect</a></li>
</ul>
</div>
</div>
</div>
<script type="text/javascript">
jQuery(function(){
var menuOffset = jQuery('.test')[0].offsetTop;
jQuery(document).bind('ready scroll',function() {
var docScroll = jQuery(document).scrollTop();
if(docScroll >= menuOffset +170) {
jQuery('.test').addClass('fixed');
} else {
jQuery('.test').removeClass('fixed').removeAttr("width");
}
});
});
</script>
CSS:
.test {
}
.test.fixed{
width: 930px;
position: fixed;
z-index: 9999;
top:0;
display:block;
min-height: 50px;
padding-right: 10px;
padding-left: 10px;
background-color: #2c3e50;
background-image: -moz-linear-gradient(top, #2c3e50, #2c3e50);
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#2c3e50), to(#2c3e50));
background-image: -webkit-linear-gradient(top, #2c3e50, #2c3e50);
background-image: -o-linear-gradient(top, #2c3e50, #2c3e50);
background-image: linear-gradient(to bottom, #2c3e50, #2c3e50);
background-repeat: repeat-x;
border: 1px solid #233140;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff2c3e50', endColorstr='#ff2c3e50', GradientType=0);
*zoom: 1;
-webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.065);
-moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.065);
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.065);
}
我很欣赏我的代码不是最好的,而且可能是一些多余的东西,但我只是从商店各处拿点点滴滴。