home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2003 April
/
PCWorld_2003-04_cd.bin
/
Novinky
/
interval
/
podklady
/
fridrich
/
257
/
newsticker.js
< prev
Wrap
Text File
|
2003-02-25
|
2KB
|
78 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.display = "block";
message[i].style.left = 0 - message[i].offsetWidth + "px";
}
var tickerID = newsTicker.ticker.length;
newsTicker.ticker[tickerID] = [elm, step, speed, delay, message.length-1];
elm.newsTickerID = tickerID;
elm.onmouseover = newsTicker.stop;
elm.onmouseout = newsTicker.start;
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) {
ticker[4] = (ticker[4]+1 == message.length) ? 0 : 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;
}
newsTicker.stop = function(e) {
id = newsTicker.getId(e);
clearTimeout(newsTicker.ticker[id][5]);
return (id) ? true : false;
}
newsTicker.start = function(e) {
id = newsTicker.getId(e);
newsTicker.roll(id);
return (id) ? true : false;
}
newsTicker.getId = function(e) {
if (!e && window.event) e = window.event;
if (!e.target) e.target = e.srcElement;
var obj = (e.currentTarget) ? e.currentTarget : e.target;
while (obj.tagName != "UL") {
obj = obj.parentNode;
if (obj.tagName == "BODY") {
return false;
}
}
return obj.newsTickerID;
}