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

JS簡單實現(xiàn)DIV相對于瀏覽器固定位置不變的方法

 更新時間:2016年06月17日 11:11:50   作者:hbiao68  
這篇文章主要介紹了JS簡單實現(xiàn)DIV相對于瀏覽器固定位置不變的方法,涉及javascript針對頁面位置的運算與動態(tài)變換技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了JS簡單實現(xiàn)DIV相對于瀏覽器固定位置不變的方法。分享給大家供大家參考,具體如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>Anchor Properties</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta content="noindex, nofollow" name="robots">
<script>
function Totop(){
  window.scrollTo(0,0);
}
function bottom(){
  //scrollHeight屬性是獲取對象的滾動高度。
  window.scrollTo(0,document.body.scrollHeight);
}
function left(){
  //alert("left");alert(document.body.scrollLeft)
  var left = 0-document.body.scrollWidth;//向左移動的像素
  window.scrollBy(left,0 );
}
function right(){
  //alert(document.body.scrollWidth);
  //整個滾動條的寬度
  window.scrollBy(document.body.scrollWidth,0);
}
function init(){
  var init_pos=oLayer.style.posTop ;
  var init_left=oLayer.style.posLeft;
  document.body.onscroll=function(){
  //document.body.scrollTop等于滾動滑塊上端離滾動的開始點的距離
    oLayer.style.posTop=document.body.scrollTop+init_pos;
  //scrollLeft設置或獲取位于對象左邊界和窗口中目前可見內容的最左端之間的距離
    oLayer.style.posLeft=document.body.scrollLeft +init_left;
  }
}
</script>
</head>
<body onload="init()">
<a onclick="bottom()">置底</a>
<div id="oLayer" style="position:absolute;left:120;top:60;z-index:2;background:green;width:120px;height:120px"> ddddd
</div>
<br>
<a onclick="right()">置&nbsp;右</a>
<div style="width:1500px;height:30px;float:left">width="2000px"</div>
<a style="float:right" onclick="left()">置&nbsp;左</a>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><a onclick="Totop()">置&nbsp;頂</a>
</body>
</html>

更多關于JavaScript相關內容感興趣的讀者可查看本站專題:《JavaScript切換特效與技巧總結》、《JavaScript查找算法技巧總結》、《JavaScript動畫特效與技巧匯總》、《JavaScript錯誤與調試技巧總結》、《JavaScript數(shù)據(jù)結構與算法技巧總結》、《JavaScript遍歷算法與技巧總結》及《JavaScript數(shù)學運算用法總結

希望本文所述對大家JavaScript程序設計有所幫助。

相關文章

最新評論