标签:meta function addclass on() ddc else remove dcl ott
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.top{
width: 100%;
height: 300px;
background: red;
}
.middle{
width: 100%;
height: 30px;
background: green;
}
.middle_active{
position: fixed;
width: 100%;
height: 30px;
top: 0;
z-index: 99;
}
.bottom{
width: 100%;
height: 1500px;
background: blue;
}
</style>
<script type="text/javascript" src="js/jquery-2.1.0.js" ></script>
</head>
<body>
<div class="top"></div>
<div class="middle"></div>
<div class="bottom"></div>
</body>
<script>
$(window).scroll(function(){
var juli=$(document).scrollTop();
if(juli>300){
$(‘.middle‘).addClass(‘middle_active‘);
}else{
$(‘.middle‘).removeClass(‘middle_active‘);
}
})
</script>
</html>
标签:meta function addclass on() ddc else remove dcl ott
原文地址:http://www.cnblogs.com/yangjiansong/p/6542346.html