js--返回顶部

$(document).ready(function(){
$("#goToTop").bind("click",EventHandle.goTop);	
//$("#goToTop").click(EventHandle.goTop);
});

var EventHandle = {
goTop:function(){
acceleration = 0.1;
time = 16;

var x1=0,
y1=0,
x2=0,
y2=0,
x3=0,
y3=0;
if(document.body){
x1 = document.body.scrollTop || 0;
y1 = document.body.scrollLeft || 0;
console.log(x1+","+y1); 
}
if(document.documentElement){
x2 = document.documentElement.scrollLeft || 0;
y2 = document.documentElement.scrollTop || 0 ;
console.log(x2+","+y2);	
}

x3 = window.scrollX || 0 ;
y3 = window.scrollY || 0 ;

//x = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
//y = document.documentElement.scrollLeft? document.documentElement.scrollLeft: document.body.scrollLeft; var x = Math.max(x1,Math.max(x2,x3)); var y = Math.max(y1,Math.max(y2,y3)); EventHandle.ConsoleLog("x,y="+x+","+y); EventHandle.ConsoleLog("acceleration="+parseFloat(acceleration.toString())); var speed = 1 +parseFloat(acceleration.toString()); x5 = Math.floor(x / speed),y5 = Math.floor( y / speed); console.log("speed="+speed+",x5="+x5+",y5="+y5); window.scrollTo(x5,y5); if(x>0 || y>0){ console.log("here"); var invokeFunction = EventHandle.goTop(acceleration,time); window.setTimeout(invokeFunction,time); } }, ConsoleLog:function(str){ console.log(str); } };

  

posted @ 2013-04-28 19:38  GM_Lv  阅读(136)  评论(0编辑  收藏  举报