61,112
社区成员
发帖
与我相关
我的任务
分享
$(document).ready(function(){
var topMain=$("#header").height();//是头部的高度加头部与nav导航之间的距离
var nav=$(".daohang");
$(window).scroll(function(){
if ($(window).scrollTop()>topMain){//如果滚动条顶部的距离大于topMain则就nav导航就添加类.nav_scroll,否则就移除
nav.addClass("daohang_scroll");
}else{
nav.removeClass("daohang_scroll");
}
});
});
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
*{
padding: 0px;
margin: 0px;
}
#nav{
position:fixed;
width: 100%;
height: 45px;
background-color:red;
}
#content{
position: absolute;
left: 0px;
right: 0px;
margin: 0px auto;
width: 810px;
height:45px;
}
ul{
list-style-type:none;
height: 100%;
}
li{
float: left;
width: 100px;
height: 100%;
margin-right:1px;
background-color:yellow;
}
</style>
</head>
<body>
<div id="nav">
<div id="content">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</div>
</body>
</html>
你使用了map,图片大小必须确定,一旦自适应的话,coords的定位就错了<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
#nav{
position:relative;
width: 100%;
height: 50px;
border: 1px solid #cccccc;
}
#content{
position: absolute;
left: 0px;
right: 0px;
margin: 0px auto;
width: 400px;
height:40px;
border: 1px solid black;
}
</style>
</head>
<body>
<div id="nav">
<div id="content"></div>
</div>
</body>
</html>
这样子布局可以解决吗?