首页 > 编程学习 > JS源码:网页滚动右下角出现返回顶部goTop
201212 月11

JS源码:网页滚动右下角出现返回顶部goTop

效果如图:

直接贴代码:


 
   Wizzer.cn 
  
#goTop {position:fixed;right:20px;bottom:20px;width:40px;height:32px;padding:8px 0 0;background-color:#69c;border-radius:6px;cursor:pointer;}
#goTop:hover {background-color:#369;}
#goTop:hover .gotop1 {border-left:12px solid #369;border-right:12px solid #369;}
#goTop .gotop1 {width:0;margin:0 auto;border-bottom:12px solid #FFF;border-left:12px solid #69c;border-right:12px solid #69c;}
#goTop .gotop2 {width:10px;height:10px;margin:0 auto;background-color:#FFF;}

 

 

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

a

function $getId(Id) { return document.getElementById(Id); } var goTop = $getId("goTop"); window.onscroll = function () { if (document.documentElement.scrollTop + document.body.scrollTop > 350) { goTop.style.display = ""; } else { goTop.style.display = "none"; } } goTop.onclick = function () { var Timer = setInterval(GoTop, 10); function GoTop() { if (document.documentElement.scrollTop + document.body.scrollTop < 1) { clearInterval(Timer); } else { document.documentElement.scrollTop /= 1.1; document.body.scrollTop /= 1.1; } } }

 

 

本文地址:https://wizzer.cn/archives/2485 , 转载请保留.

One Response to “JS源码:网页滚动右下角出现返回顶部goTop”

  1. #1 王伟 回复 | 引用 Post:2013-01-24 16:16

    这个东西不错,回头试用一下

发表评论