// javascript document /** @ 回到页面顶部 @ 2011-12-16 **/ $(function(){ (function(w, n) { var obj=document.getelementbyid("gotopbtn"); function m(op) { var step = op.step || 10; //动画的帧频(ms) var time = op.time || 50; //动画的帧数 var stime = 0; document.getelementbyid(op.handle).onclick = function() { var top = g(); if(top > 0) { stime = 0; (function() { s(math.ceil(t(stime, top, -top, time))); if(stime < time) { stime++; settimeout(arguments.callee, step); } })(); } }; } //缓动算法 function t(t, b, c, d) { return -c *(t/=d)*(t-2) + b; } //获取页面scrolltop function g() { //ff / chrome safari / ie return document.documentelement.scrolltop || window.pageyoffset || document.body.scrolltop; } //设置页面scrolltop function s(n) { //chrome safari / ff / ie (/(chrome|version)/i).test(navigator.useragent)? document.body.scrolltop = n : document.documentelement? document.documentelement.scrolltop = n : document.body.scrolltop = n; } window.onscroll=function(){g()>300?obj.style.display="block":obj.style.display="block";} w[n] = m; })(window, 'gomalltop'); //调用 time 为时间 gomalltop({handle: "gotopbtn", time: 10}); })