Thursday
July 30, 2015

Homework Help: JAVASCRIPT

Posted by Kevin on Thursday, April 21, 2011 at 8:57pm.

Start button won't work for a scolling marquee. Below is the javascript code.


window.onload = defineMarquee;

var timeID;
var marqueeTxt = new Array;
var marqueeOff = true;

function defineMarquee() {

var topValue = 0;
var allElems = document.getElementsByTagName("*");

for (var i = 0; i < allElems.length; i++) {
if (allElems[i].className == "marqueeTxt") marqueeTxt.push(allElems[i]);
}
for (var i = 0; i < marqueeTxt.length; i++) {
if (window.getComputedStyle) {
topValue = marqueeTxt[i].document.defaultView.getPropertyValue("top");
}
else if (marqueeTxt[i].currentStyle) {
topValue = marqueeTxt[i].currentStyle("top");
}
}
document.getElementById("startMarquee").onclick = startMarquee;
document.getElementById("stopMarquee").onclick = stopMarquee;
}

function startMarquee() {
if (marqueeOff == true) {
timeID = setInterval("moveMarquee()", 50);
marqueeOff = false;
}
}

function stopMarquee() {
clearInterval(timeID);
marqueeOff = true;
}

function moveMarquee() {

var topPos = 0;

for (var i = 0; i < marqueeTxt.length; i++) {
if(marqueeTxt[i].getComputedStyle){
topPos = parseInt(marqueeTxt[i].getPropertyValue("top"));
}
else
if(marqueeTxt[i].currentStyle) {
topPos = parseInt(marqueetxt[i].currentStyle("top"));
}
if(topPos < -110) {
topPos = 700;
}
else {
topPos -= 1;
}
marqueeTxt[i].style.top = topPos + "px";
}
}

Answer this Question

First Name:
School Subject:
Answer:

Related Questions

More Related Questions

Members