Guest User

Untitled

a guest
May 24th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. var Scroller = Class.create({
  2. initialize:function(container, content, speed, scrollDelay){
  3. this.timerID = null;
  4. this.timer = new Timer(this);
  5. this.scrollDelay = 15;
  6. this.speed = 5;
  7. this.container = null;
  8. this.content = null;
  9. this.containerWidth = null;
  10. this.containerHeight = null;
  11. this.contentWidth = null;
  12. this.contentHeight = null;
  13. this.currentX = 0;
  14. this.currentY = 0;
  15. this.offsetX = 0;
  16. this.offsetY = 0;
  17.  
  18. if ( (speed > 0) && (speed <= 10) )
  19. this.speed = speed;
  20. if ( (scrollDelay > 0) && (scrollDelay <= 100) )
  21. this.scrollDelay = scrollDelay;
  22.  
  23. this.container = $(container);
  24. this.content = $(content);
  25. this.containerWidth = $(container).clientWidth;
  26. this.containerHeight = $(container).clientHeight;
  27. this.contentWidth = $(content).clientWidth;
  28. this.contentHeight = $(content).clientHeight;
  29. },
  30.  
  31.  
  32. moveUp: function (){
  33. if ( this.currentY >= 0 ) {
  34. this.clearTimer();
  35. return true;
  36. }
  37. this.currentY = this.currentY + this.speed;
  38. this.content.style.top = this.currentY+'px';
  39. this.timerID = this.startTimer('moveUp');
  40. },
  41.  
  42. moveDown: function(){
  43. if ( this.offsetY < 0 || Math.abs(offsetY) < Math.abs(currentY) ) {
  44. this.clearTimer();
  45. return true;
  46. }
  47. this.currentY = this.currentY - this.speed;
  48. this.content.style.top = this.currentY+'px';
  49. this.timerID = this.startTimer('moveDown');
  50. },
  51.  
  52. moveLeft: function(){
  53. if ( this.currentX >= 0 ) {
  54. this.clearTimer();
  55. return true;
  56. }
  57. this.currentX = this.currentX + this.speed;
  58. this.content.style.left = this.currentX+'px';
  59. this.timerID = this.startTimer('moveLeft');
  60. },
  61.  
  62. moveRight: function(obj){
  63. if ( this.offsetX < 0 || Math.abs(this.offsetX) < Math.abs(this.currentX) ) {
  64. this.clearTimer();
  65. return true;
  66. }
  67. this.currentX = this.currentX - this.speed;
  68. this.content.style.left = this.currentX+'px';
  69. this.timerID = this.startTimer('moveRight');
  70. },
  71.  
  72. clearTimer: function(){
  73. this.timer.clearTimeout(this.timerID);
  74. },
  75.  
  76. startTimer: function (functionName){
  77. this.timerID = this.timer.setTimeout(functionName, this.scrollDelay);
  78. }
  79. });
Add Comment
Please, Sign In to add comment