Advertisement
Guest User

goTop

a guest
Apr 18th, 2011
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getGroupItems(opts) {
  2.  
  3.     jQuery.each(imageList, function(i, val) {
  4.  
  5.           opts.itemArray.push(val);
  6.  
  7.     });
  8.  
  9. }
  10.  
  11.  
  12.  
  13. function goTop(acceleration, time) {
  14.  
  15.     acceleration = acceleration || 0.5;
  16.  
  17.     time = time || 16;
  18.  
  19.  
  20.     var dx = 0;
  21.  
  22.     var dy = 0;
  23.  
  24.     var bx = 0;
  25.  
  26.     var by = 0;
  27.  
  28.     var wx = 0;
  29.  
  30.     var wy = 0;
  31.  
  32.  
  33.     if (document.documentElement) {
  34.  
  35.         dx = document.documentElement.scrollLeft || 0;
  36.  
  37.         dy = document.documentElement.scrollTop || 0;
  38.  
  39.     }
  40.  
  41.     if (document.body) {
  42.  
  43.         bx = document.body.scrollLeft || 0;
  44.  
  45.         by = document.body.scrollTop || 0;
  46.  
  47.     }
  48.  
  49.     var wx = window.scrollX || 0;
  50.  
  51.     var wy = window.scrollY || 0;
  52.  
  53.  
  54.     var x = Math.max(wx, Math.max(bx, dx));
  55.  
  56.     var y = Math.max(wy, Math.max(by, dy));
  57.  
  58.  
  59.     var speed = 1 + acceleration;
  60.  
  61.     window.scrollTo(Math.floor(x / speed), Math.floor(y / speed));
  62.  
  63.     if(x > 0 || y > 0) {
  64.  
  65.         var invokeFunction = "goTop(" + acceleration + ", " + time + ")"
  66.  
  67.         window.setTimeout(invokeFunction, time);
  68.  
  69.     }
  70.  
  71. }
  72.  
  73.  
  74.  
  75. window['goTop'] = goTop;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement