It’s possible to use JavaScript to move an object (an image, or text, or whatever) around your screen. In fact, you can make an object appear to move in three dimensions, so that it looks as through it passes behind other objects in the document. In this example, you’ll see how that annoying advertisement in the previous task can be made even more annoying.
This again requires three documents; however, the HTML and CSS are identical to that in the previous version. Here, we’ll just show the JavaScript file (Script 12.13). Now, as soon as the user wants to close the advertisement layer, it starts to move away from them. Thankfully, it will stop before it goes off the screen (Figure 12.8), allowing them to finally close it!
To move an object:
✓ Tip
You might be wondering: if offsetLeft is numeric, why jump through all those hoops to instead change the style.left property? We have to do that because offsetLeft is read-only; that is, you can read its value, but you can’t change it. There aren’t any cross-browser, writeable, numeric positioning elements.
3.140.245.196