Funky Munky > Examples > Loading > Script Explanation
.
First of all, we had three span tags named L1, L2, and L3. The object l1 was the red rectangle that moved left across the screen. The object L2 was the white one that sat there. The object L3 was a hidden object that covered up L1. Object L1 started at left 240 and was covered by object L3, which was positioned at left 240 also. Then, object L1 moved across the screen to the right by increments of five covering L2 as it went. Object L2 was positioned at 340. Each object is 100 pixels in width. When L2 reached left 340, it was repositioned at 240.

Note: Lines are numbered for clarification.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<script language="JavaScript">
<!--

var o1 = "";

function load() {
  if (document.all) { o1 = l1.style; } else { o1 = document.l1; }
  load2();
}

function load2() {
  o1.left = parseInt(o1.left) + 5;
  if (parseInt(o1.left) == 340) { o1.left = 240; }  
setTimeout("load2()", 10);
}

//-->
</script>

When the page loads, the function load() at line #6 was called up. On line #7, it sets the variable o1 to the object L1. Line #8 starts load2() at line #11. On line #12, it moves L1 forward by five pixels. Line #13 checks to see where L1 is. If it is at 340, it repositions it to 240. And finally Line #14 starts load2() over again.

[ Funky Munky ] [ Back to main page ] [ Examples and Experiments ]