|
Scrolling Code
Now we have a table moving across the page with a limit...but it's going beyond that limit! Here is where the "else" comes into play. The else is used to reposition the table once it reaches the limiter. But here we cycle the function endlessly. First we must start the function. We do this by adding an onload="tables()" command to the body tag. That initiates the function. Keep in mind that a function will just sit there doing nothing unless it is called upon. We cycle this function by using a timer. This line of code setTimeout("tables()",20) tells "Bowser", the webtv browser, to wait 20 milliseconds then go to the beginning of the function which we have named "tables". Even though there are limits on this "table" it will always meet the conditions needed to move. The "else" repositions it once the original condition isn't met, and the timer keeps it cycling. Let's look at the table and the limits placed on it. if (document.all.table1.style.posLeft < 560) {document.all.table1.style.posLeft +=2;} else {document.all.table1.style.posLeft=-100; } This says if table1 is less than 560 pixels from the left side; then add 2 pixels to its current position. So table one will keep adding two pixels from it's position until it reaches 560. Or ELSE if table one is at 560 or more, put it back to -100 pixels left. setTimeout("tables()",20); This is the timer. It tells how often to run the function. In this case, every 20 milliseconds. The table will reach 560 and 20 milliseconds later will reposition at -100 pixels left. Remember -100 pixels means it is off the screen to the left side 100 pixels.... |
| table1 |