Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Scroller = Class.create({
- initialize:function(container, content, speed, scrollDelay){
- this.timerID = null;
- this.timer = new Timer(this);
- this.scrollDelay = 15;
- this.speed = 5;
- this.container = null;
- this.content = null;
- this.containerWidth = null;
- this.containerHeight = null;
- this.contentWidth = null;
- this.contentHeight = null;
- this.currentX = 0;
- this.currentY = 0;
- this.offsetX = 0;
- this.offsetY = 0;
- if ( (speed > 0) && (speed <= 10) )
- this.speed = speed;
- if ( (scrollDelay > 0) && (scrollDelay <= 100) )
- this.scrollDelay = scrollDelay;
- this.container = $(container);
- this.content = $(content);
- this.containerWidth = $(container).clientWidth;
- this.containerHeight = $(container).clientHeight;
- this.contentWidth = $(content).clientWidth;
- this.contentHeight = $(content).clientHeight;
- },
- moveUp: function (){
- if ( this.currentY >= 0 ) {
- this.clearTimer();
- return true;
- }
- this.currentY = this.currentY + this.speed;
- this.content.style.top = this.currentY+'px';
- this.timerID = this.startTimer('moveUp');
- },
- moveDown: function(){
- if ( this.offsetY < 0 || Math.abs(offsetY) < Math.abs(currentY) ) {
- this.clearTimer();
- return true;
- }
- this.currentY = this.currentY - this.speed;
- this.content.style.top = this.currentY+'px';
- this.timerID = this.startTimer('moveDown');
- },
- moveLeft: function(){
- if ( this.currentX >= 0 ) {
- this.clearTimer();
- return true;
- }
- this.currentX = this.currentX + this.speed;
- this.content.style.left = this.currentX+'px';
- this.timerID = this.startTimer('moveLeft');
- },
- moveRight: function(obj){
- if ( this.offsetX < 0 || Math.abs(this.offsetX) < Math.abs(this.currentX) ) {
- this.clearTimer();
- return true;
- }
- this.currentX = this.currentX - this.speed;
- this.content.style.left = this.currentX+'px';
- this.timerID = this.startTimer('moveRight');
- },
- clearTimer: function(){
- this.timer.clearTimeout(this.timerID);
- },
- startTimer: function (functionName){
- this.timerID = this.timer.setTimeout(functionName, this.scrollDelay);
- }
- });
Add Comment
Please, Sign In to add comment