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

javascript回到頂部特效

 更新時間:2016年07月30日 10:06:01   作者:行者杰客  
這篇文章主要為大家詳細(xì)介紹了javascript回到頂部特效,具有一定的參考價值,感興趣的朋友可以參考一下

本文實例為大家分享了javascript回到頂部效果,供大家參考,具體內(nèi)容如下

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
 <title>回到頂部效果(原生js)</title>
 <style type="text/css">
  body{
   margin: 0;

  }
  .bg{
   width: 1022px;
   margin: 0 auto;
  }
  .btn{
   display: none;
   width: 75px;
   height: 75px;
   background:url(../images/網(wǎng)頁top小圖標(biāo)(返回頂部)/返回頂部-085.png) no-repeat left top;
   position: fixed;
   left: 50%;
   margin-left: 530px;
   bottom: 10px;
   text-indent: -9999px;
   outline: none;
  }
  .btn:hover{
   background-position: 0 -75px;
  }
 </style>
 
 <script>  
 var timer=null;
 var isScroll=true;
 //1.2構(gòu)造oScroll函數(shù)
 function oScroll(){
  var osTop=document.documentElement.scrollTop||document.body.scrollTop;//1.1滾動高度,兼容
  var oSpeed=Math.ceil(osTop/4);//滾動速度
  document.documentElement.scrollTop=document.body.scrollTop=osTop-oSpeed;
  if(osTop==0){//判斷到達頂部,清理定時器
   clearInterval(timer);
  }
  isScroll=true; 
 }
      
 window.onload=function() {
  var obtn=document.getElementById('btn');//獲取按鈕元素
  var clientHeight=document.documentElement.clientHeight||document.body.clientHeight;

  // 1.點擊返回按鈕事件 
  btn.onclick=function(){//為按鈕綁定點擊事件
   timer=setInterval(oScroll,50); 
  } 
  window.onscroll=function() {
   var osTop=document.documentElement.scrollTop||document.body.scrollTop;//1.1滾動高度,兼容
   if (osTop>clientHeight) {
    btn.style.display="block";
   }else{
    btn.style.display="none";
   }
   if(!isScroll){
    clearInterval(timer);
   }
   isScroll=false;
  }
 } 


 </script>

</head>
<body>
 <div class="bg">
  <img src="../images/jz.jpg">
 </div>
 <a href="javascript:void(0);" title="返回頂部" id="btn" class="btn">返回頂部</a>
</body>
</html>

以上就是本文的全部內(nèi)容,希望對大家學(xué)習(xí)JavaScript程序設(shè)計有所幫助。

相關(guān)文章

最新評論