aongao
回到顶部
<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">// <![CDATA[
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>

 

参考:博客园

分类:

技术点:

相关文章:

  • 2021-12-05
  • 2022-01-01
  • 2022-01-01
  • 2021-12-30
  • 2021-09-29
  • 2021-10-16
  • 2021-05-17
  • 2021-08-05
猜你喜欢
  • 2022-01-07
  • 2021-09-29
  • 2021-12-05
  • 2021-09-29
  • 2021-12-15
  • 2021-06-09
  • 2021-10-16
相关资源
相似解决方案