jquery實現(xiàn)的超出屏幕時把固定層變?yōu)槎ㄎ粚拥拇a
淘寶產品列表 http://search1.taobao.com/browse/50010388/…
騰訊財經產業(yè)經濟 http://finance.qq.com/industry/index.htm
如何實現(xiàn)?
scrollTop是什么?當元素內部的內容高度超過元素本身的高度時就會出現(xiàn)滾動條,隨著拖動滾動條而被隱去的上面部分的高度就是scrollTop值。
這種定位層就是當頁面觸發(fā)onscroll事件時,取得scrollTop值并寫入定位層CSS屬性,使之保持位置。
下面是實例代碼
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>定位層</title>
<script type="text/javascript" src="http://img.jb51.net/jslib/jquery/jquery.js"></script>
<style type="text/css">
body{padding:10px;margin:0;}
#box{width:960px;margin:0 auto;}
#box1{width:250px;height:25px;position:relative;}
#box1_1{width:250px;height:25px;line-height:25px;background:#f00;color:#fff;}
p{font-size:24px;margin:10px 0;}
</style>
<script type="text/javascript">
function tools(){
var top=$(document).scrollTop();
if(($.browser.msie==true)&&($.browser.version==6.0)){
if(top>168)$("#box1_1").css({position:"absolute",top:top-168});
}else{
if(top>168)$("#box1_1").css({position:"fixed",top:"-"&top+"px"});
}
if(top<=168)$("#box1_1").css({position:"static",top:0});
}
$(function(){
window.onscroll=tools;
window.onresize=tools;
});
</script>
</head>
<body>
<div id="box">
<p>往下拖動滾動條↓<a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<div id="box1"><div id="box1_1">這里是定位層</div></div>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
<p><a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">jb51.net</a> <a href="http://www.dbjr.com.cn">腳本之家</a></p>
</div>
</body>
</html>
相關文章
jquery獲取file表單選擇文件的路徑、名字、大小、類型
今天小編就為大家分享一篇關于jquery獲取file表單選擇文件的路徑、名字、大小、類型,小編覺得內容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-01-01html、css和jquery相結合實現(xiàn)簡單的進度條效果實例代碼
這篇文章主要介紹了html、css和jquery相結合實現(xiàn)簡單的進度條效果的實例代碼,這個進度條特別簡單,首先html里面的話就是一個div里面嵌套一個div,然后寫好想要的樣式就行了,具有一定的參考借鑒價值,感興趣的朋友一起看看吧2016-10-10jquery mobile實現(xiàn)撥打電話功能的幾種方法
在做一個便民服務電話,用到移動web中列出的電話,點擊需要實現(xiàn)調用通訊錄,撥打電話功能,有需要的朋友可以參考一下2013-08-08