欧美日韩一区二区三区四区不卡,日韩欧美视频一区二区三区四区,久久精品欧美一区二区三区不卡,国产精品久久久乱弄

咨詢電話:186 7916 6165 咨詢電話:186 7916 6165 (微信同號)    在線QQ:181796286
NEWS BLOG ·
學無止境
關注開優網絡 關注前沿
JS設置網頁刷新或者重新加載后滾動條的位置不變
“您是第幾位訪客”的來訪統計js

JS打造實用的隨屏滾動DIV層

發表日期:2016-07-18    文章編輯:南昌開優網絡    瀏覽次數:4622    標簽:JS應用

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>JS打造實用的隨屏滾動DIV層</title>
<style>
	html,body{
		padding:0;
		margin:0;
	}
</style>
</head>
<body>
	<div id="aa" style="width:200px;height:200px;background:#c0c0c0;" >我在隨屏滾</div>
	<div id="bb" style="width:200px;height:200px;background:#c0c0c0;" >我靜止不動</div>
	<div style="width:100%;height:500px;background:#000"></div>
	<div style="width:100%;height:500px;background:green"></div>
	<div style="width:100%;height:500px;background:red"></div>
</body>
</html>
<script>
function scroll(p){
  var d = document,dd = d.documentElement,db = d.body,w = window,o = d.getElementById(p.id),ie = /msie/i.test(navigator.userAgent),style;
    	if(o){
    	o.style.cssText +=";position:"+(p.f&&!ie?'fixed':'absolute')+";"+(p.l==undefined?'right:0;':'left:'+p.l+'px;')+(p.t!=undefined?'top:'+p.t+'px':'bottom:0');
    		if(p.f&&ie){
			o.style.cssText +=';left:expression(body.scrollLeft + '+(p.l==undefined?db.clientWidth-o.offsetWidth:p.l)+' + "px");top:expression(body.scrollTop +'+(p.t==undefined?db.clientHeight-o.offsetHeight:p.t)+'+ "px" );'
				db.style.cssText +=";background-image:url(about:blank);background-attachment:fixed;"
			}else{
				if(!p.f){
					w.onresize = w.onscroll = function(){
						var timer,timer1;
						return function(){
							if(timer)
								clearTimeout(timer);
							timer = setTimeout(function(){
								timer1 = setInterval(function(){
									var st = db.scrollTop,c;
									c = st  - o.offsetTop + (p.t!=undefined?p.t:(w.innerHeight||db.clientHeight)-o.offsetHeight);
									if(c!=0){
										o.style.top = o.offsetTop + Math.ceil(Math.abs(c)/10)*(c<0?-1:1) + 'px';
									}else{
										clearInterval(timer1);		
									}
								},10)
							},100)//控制滾動的頻率越大頻率越慢
						}
					}()
				}
			}
    	}  
    }
    scroll({
    	id:'aa'
	
    })
	 scroll({
		id:'bb',
		l:0,
		t:200,
		f:1
	 })

</script>
主站蜘蛛池模板: 磴口县| 龙井市| 牟定县| 额敏县| 德清县| 米易县| 许昌市| 临清市| 临猗县| 隆化县| 绥德县| 澄迈县| 荣昌县| 禄劝| 宜城市| 肃宁县| 遂川县| 新源县| 金平| 仙居县| 甘肃省| 定兴县| 永顺县| 沾益县| 乌审旗| 象山县| 磐安县| 南平市| 北海市| 平塘县| 马尔康县| 崇文区| 温泉县| 内江市| 黎川县| 湖州市| 临夏市| 谷城县| 临猗县| 南澳县| 托克托县|