我在twitter bootstrap中有一个带有顶部固定导航的网站 我有两个导航,一个在顶部,另一个在中间。顶部有一个固定的位置,但要求是我们滚动到中间并达到中间导航,添加固定类到中间导航并从顶部导航中删除固定类。
提前感谢您的帮助。 穆尔塔扎
答案 0 :(得分:0)
您可以使用以下内容。
演示:http://jsbin.com/hifakesu/1/
JS :
$( window ).scroll(function() {
var scrollVal = $( window ).scrollTop();
if(scrollVal==100){
$(".test").addClass("fixed");
}
});
HTML :
<html>
<body>
<div class="test"></div>
</body>
</html>
CSS :
.test{
height:700px;
float:left;
width:250px;
background:#CCC;
}
希望这会有所帮助。干杯
答案 1 :(得分:0)
试试这个
$( window ).scroll(function() {
if($( window ).scrollTop()==$("yourId").offset().top){
$("yourId").addClass("fixed");
}
});