
Originally Posted by
esn003
Did you solve the issue?
yeah i used a .js file (1kb only in size after packing) to achieve that, it has support to stop/start the text on mouseover/out aswell as provides the ability to change the speed of text.
here it is if anyone else is interested:
Code:
function Scroller(canvasId, textId, speed, moveAmount, horizontal, mouseOver) {
this.timerID = null;
this.currPos = 0;
this.speed = speed;
this.moveAmount = moveAmount;
this.canvasId = canvasId;
this.textId = textId;
this.horizontal = horizontal;
this.mouseOver = mouseOver;
if (this.horizontal) {
this.canvasSize = document.getElementById(this.canvasId).offsetWidth;
this.textSize = document.getElementById(this.textId).offsetWidth;
} else {
this.canvasSize = document.getElementById(this.canvasId).offsetHeight;
this.textSize = document.getElementById(this.textId).offsetHeight;
}
this.start = function() {
this.registerEvents();
this.stop();
this.move(this.currPos, this.moveAmount, this.speed);
}
this.registerEvents = function() {
var context = this;
if (this.mouseOver) {
document.getElementById(this.canvasId).onmouseover = function() {
context.stop();
};
}
document.getElementById(this.canvasId).onmouseout = function() {
context.stop();
context.move(context.currPos, context.moveAmount, context.speed);
};
}
this.move = function(nextPosition, amountOfPixels, miliseconds) {
nextPosition -= amountOfPixels;
if (nextPosition == -this.textSize) {
nextPosition = this.canvasSize;
}
if (this.horizontal) {
document.getElementById(this.textId).style.right = nextPosition + 'px';
} else {
document.getElementById(this.textId).style.top = nextPosition + 'px';
}
var context = this;
this.timerID = setTimeout(function() {
context.move(nextPosition, amountOfPixels, miliseconds);
}, miliseconds);
}
this.stop = function() {
if (this.timerID !== null) {
clearTimeout(this.timerID);
if (this.horizontal) {
this.currPos = parseInt(document.getElementById(this.textId).style.right, null);
} else {
this.currPos = parseInt(document.getElementById(this.textId).style.top, null);
}
}
}
}
if (typeof(addEventSimple) == 'undefined') {
addEventSimple = function(obj, evt, fn) {
if (obj.addEventListener)
obj.addEventListener(evt, fn, false);
else if (obj.attachEvent)
obj.attachEvent('on' + evt, fn);
}
}
if (typeof(addEventSimple) == "function") {
addEventSimple(window, "load", function() {
var myScroller = new Scroller("canvas", "text", 50, 1, false, true);
myScroller.start();
});
}
Bookmarks