Created
June 29, 2013 08:54
-
-
Save QETHAN/5890434 to your computer and use it in GitHub Desktop.
返回顶部
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var BackTop = function(btnId) { | |
var btn = document.getElementById(btnId); | |
var d = document.documentElement ? document.documentElement : document.body; | |
window.onscroll = set; | |
btn.onclick = function() { | |
btn.className = 't_hide'; | |
window.onscroll = null; | |
this.timer = setInterval(function(){ | |
d.scrollTop -= Math.ceil(d.scrollTop*0.8); | |
if(d.scrollTop==0) { | |
clearInterval(this.timer); | |
window.onscroll=set; | |
} | |
},10); | |
}; | |
function set() { | |
btn.className = d.scrollTop > 1620 ? 't_show' : 't_hide'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment