亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

js實(shí)現(xiàn)簡(jiǎn)單的左右兩邊固定廣告效果實(shí)例

 更新時(shí)間:2015年04月10日 10:55:11   作者:jingangel  
這篇文章主要介紹了js實(shí)現(xiàn)簡(jiǎn)單的左右兩邊固定廣告效果,實(shí)例分析了javascript實(shí)現(xiàn)固定廣告的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了js實(shí)現(xiàn)簡(jiǎn)單的左右兩邊固定廣告效果的方法。分享給大家供大家參考。具體分析如下:

大多數(shù)網(wǎng)站都有左右兩邊的固定廣告位,下面呢就是實(shí)現(xiàn)這個(gè)效果的最簡(jiǎn)單的代碼,可能在ie下滾動(dòng)的時(shí)候會(huì)有一點(diǎn)抖動(dòng),這個(gè)問(wèn)題以后再解決了,先實(shí)現(xiàn)再說(shuō)。

要點(diǎn)一:

var adtop = adleft.offsetTop;

獲得元素距離上邊的位置,在滾動(dòng)的時(shí)候需要用到。

要點(diǎn)二:

復(fù)制代碼 代碼如下:
adleft.style.top=adtop+(document.documentElement.scrollTop || document.body.scrollTop)+"px";
滾動(dòng)時(shí),給元素的上邊位置賦值為元素本身距離上邊的距離加上滾動(dòng)的距離。
 
上代碼:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>無(wú)標(biāo)題文檔</title>
<style>
body{margin:0; padding:0}
#adleft,#adright{
width:30px;
height:100px;
padding:20px;
font:14px/20px arial;
text-align:center;
background:#06c;
position:absolute;
cursor:pointer;
color:#fff
}
#adleft{left:0; top:150px; }
#adright{right:0; top:150px;}
</style>
<script>
window.onload = function(){
 var adleft = document.getElementById("adleft");
 var adright = document.getElementById("adright");
 var adtop = adleft.offsetTop;
 window.onscroll = function(){
  adleft.style.top = adtop + (document.documentElement.scrollTop || document.body.scrollTop) +"px"; 
  adright.style.top = adtop + (document.documentElement.scrollTop || document.body.scrollTop) +"px"; 
 }
} 
</script>
</head>
<body style="height:2000px;">
<h1>左右廣告</h1>
<div id="adleft">左邊廣告</div>
<div id="adright">右邊廣告</div>
</body>
</html>

希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論