Skip to content

Instantly share code, notes, and snippets.

@QETHAN
Created June 29, 2013 08:54
Show Gist options
  • Save QETHAN/5890434 to your computer and use it in GitHub Desktop.
Save QETHAN/5890434 to your computer and use it in GitHub Desktop.
返回顶部
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