jquery版樓層滾動特效

來源:互聯網
上載者:User

標籤:his   off   block   read   ima   line   document   ddc   jquery   

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>樓層滾動特效</title>
</head>
<script src="js/jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
#F1{
width:100%;
height: 500px;
background-color: #00008B;
}
#F2{
width:100%;
height: 500px;
background-color: #00FF00;
}
#F3{
width:100%;
height: 500px;
background-color: #00FFFF;
}
#F4{
width:100%;
height: 500px;
background-color: #1AC78C;
}
#F5{
width:100%;
height: 500px;
background-color: #6495ED;
}
#ulbox{
position: fixed;
left:30px;
top:25%;
}
#ulbox li{
list-style: none;
width: 50px;
height: 50px;
line-height: 50px;
text-align: center;
border: 1px solid #000;
background-color: #fff;
}
a{
display: block;
text-decoration: none;
cursor: pointer;
}
.current{
background-color: #FF0000;
}
</style>
<body>
<div id="content">
<div id="F1" class="item">
樓層一
</div>
<div id="F2" class="item">
樓層二
</div>
<div id="F3" class="item">
樓層三
</div>
<div id="F4" class="item">
樓層四
</div>
<div id="F5" class="item">
樓層五
</div>
</div>
<ul id=‘ulbox‘>
<li><a href="#F1" class="current">F1</a></li>
<li><a href="#F2">F2</a></li>
<li><a href="#F3">F3</a></li>
<li><a href="#F4">F4</a></li>
<li><a href="#F5">F5</a></li>
</ul>
</body>
<script type="text/javascript">
$(document).ready(function(){
$(window).scroll(function(){
var top=$(document).scrollTop();
var ulbox=$(‘#ulbox‘);
var items=$(‘#content‘).find(‘.item‘);
var currentId=‘‘;//當前所在樓層的#id
items.each(function(){
var _this=$(this);
var itemstop=_this.offset().top;//遍曆出每個樓層距離頂部的高度
if(top>itemstop-200){
currentId=‘#‘+_this.attr(‘id‘);
}else{
return false;
}
})
var currentLink=ulbox.find(‘.current‘);
if(currentId&&currentLink.attr(‘href‘)!=currentId){
currentLink.removeClass(‘current‘);
ulbox.find(‘[href=‘+currentId+‘]‘).addClass(‘current‘);
}
});

});


</script>
</html>

 

jquery版樓層滾動特效

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.