JS Alert... Please reload
JAVASCRIPT and
DYNAMIC CONTENT

2. Move Div With Limits
In the last 2 scripts we learned to move the contents of a div in 4 directions. If you held any of the buttons on the last page, the moving square kept going off into cyberspace and never came back. Wouldn't it be nice if it would stop it at a certain point before it leaves the screen? Well, it can. We'll add a condition that must be met BEFORE the table can move.


NOTE:The brackets we use in HTML are also mathematical symbols with special meaning.
This > means "more than".....
This < means "less than"


In the code below you'll see a line that begins with "if".....This is the conditional statement and says: IF table one is "more than" 20 pixels from the left hand side....proceed with the movement. In this case the movement is 10 pixels per click and moves left.

function limitedL()
{
if (document.all.table1.style.posLeft > 20)
document.all.table1.style.posLeft -=10
}


When the table reaches the 20px mark it will stop.

In the code below you'll see the line that begins with "if".....This is the conditional statement for limitedD and says: IF table one is "less than" 230 pixels from the top....proceed with the movement. In this case the movement is 10 pixels per click and moves down. Once the square reaches 230 pixels from the top it will go no further.

function limitedD()
{
if (document.all.table1.style.posTop< 230)
document.all.table1.style.posTop +=10
}




Here is the code for the above script. These scripts are perfect for making a maze. See if you can make one.

JS Lessons by Ken

1. Move div without limits
1. txt page ~ ~ ~ 1. c/c/p codes

2. Move div with limits
2. txt page ~ ~ ~ 2. c/c/p codes

3. Using a single function for multiple actions
3. txt page ~ ~ ~ 3. c/c/p codes

4. Repositioning using the else command
4. txt page ~ ~ ~ 4. c/c/p codes

5. Intro to the setTimeout. Using it to scroll a div
5. txt page ~ ~ ~ 5. c/c/p codes

6. DHTML
6. txt page ~ ~ ~ 6. c/c/p codes

7. More DHTML
7. txt page ~ ~ ~ 7. c/c/p codes

8. Visibility
8. txt page ~ ~ ~ 8. s/s/p codes

Tandem Tooters    Paulie's Interface NG
table1