浮動div,回到頂部


<div style="height: 5000px">這是頂部</div>
<div id="FloatDIV" style="position: absolute;top: 0px; z-index:9999; background: #fff000;cursor: pointer"
 onclick="window.scrollTo(0,0);">
    回到頂部
</div>

<script type="text/javascript"> 
    var MarginLeft = 10;    //浮動層離瀏覽器右側的距離
  var MarginTop = document.body.clientHeight - 80;   //浮動層離瀏覽器頂部的距離(瀏覽器高度-div高度)
  var Width = 25;            //浮動層寬度
  var Heigth= 80;           //浮動層高度
  
  //設置浮動層寬、高
  function Set()
  {
      document.getElementById("FloatDIV").style.width = Width + 'px';
      document.getElementById("FloatDIV").style.height = Heigth + 'px';
  }
  
  //實時設置浮動層的位置
  function Move()
  {
        var b_top = window.pageYOffset  
                || document.documentElement.scrollTop  
                || document.body.scrollTop  
                || 0;
        var b_width= document.body.clientWidth;
      document.getElementById("FloatDIV").style.top = b_top + MarginTop + 'px';
      document.getElementById("FloatDIV").style.left = b_width - Width - MarginLeft + 'px';
      setTimeout("Move();",100);
  }
  
  Set();
  Move();

</script> 

 

 

回到頂部


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM