home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2003 April
/
PCWorld_2003-04_cd.bin
/
Novinky
/
interval
/
podklady
/
fridrich
/
257
/
newsticker-simple.js
< prev
next >
Wrap
Text File
|
2003-02-25
|
2KB
|
52 lines
var newsTicker = {};
// elm, step, speed, delay, actual, timer
newsTicker.ticker = [];
newsTicker.init = function(elm, step, speed, delay) {
if (elm && (elm.tagName == "UL") && document.getElementsByTagName) {
if (isNaN(step)) {var step = 2};
if (isNaN(speed)) {var speed = 25};
if (isNaN(delay)) {var delay = 1000};
var message = elm.getElementsByTagName("LI");
for (var i = 0; i < message.length; i++) {
message[i].style.left = 0 - message[i].offsetWidth + "px";
}
var tickerID = newsTicker.ticker.length;
newsTicker.ticker[tickerID] = new Array(elm, step, speed, delay, message.length-1);
newsTicker.roll(tickerID);
return true;
}
return false;
}
newsTicker.roll = function(id) {
if (!isNaN(id) && newsTicker.ticker[id]) {
var ticker = newsTicker.ticker[id];
var message = ticker[0].getElementsByTagName("li");
var actualMessage = message[ticker[4]];
if (parseInt(actualMessage.style.left) <= 0 - actualMessage.offsetWidth) {
if (ticker[4] + 1 == message.length) {
ticker[4] = 0;
} else {
ticker[4] = ticker[4] + 1;
}
actualMessage = message[ticker[4]];
actualMessage.style.left = ticker[0].offsetWidth + (ticker[0].offsetWidth % ticker[1]);
}
actualMessage.style.left = parseInt(actualMessage.style.left) - ticker[1] + "px";
ticker[5] = setTimeout("newsTicker.roll(" + id + ")", (parseInt(actualMessage.style.left) == 0) ? ticker[3] : ticker[2]);
return true;
}
return false;
}