Chapter 7. Animating Your Pages

In This Chapter

  • Moving an object on the screen

  • Responding to keyboard input

  • Reading mouse input

  • Running code repeatedly

  • Bouncing off the walls

  • Swapping images

  • Reusing code

  • Using external script files

JavaScript has a serious side, but it can be a lot of fun, too. You can easily use JavaScript to make things move, animate, and wiggle. In this chapter, you find out how to make your pages dance. Even if you aren't interested in animation, you can discover important ideas about how to design your pages and code more efficiently.

Tip

I know what you're thinking: You can use this stuff to make a really cool game. It's true. You can make games with JavaScript, but you eventually run into JavaScript's design limitations. I prefer Flash and Python as languages to learn game development. Now that you mention it, I've written other Wiley books on exactly these topics. See you there! (Check out Beginning Flash Game Programming For Dummies and Game Programming: The L Line for Python development.)

Making Things Move

You may think you need Flash or Java to put animation in your pages, but that's not the only way. You can use JavaScript to create some pretty interesting motion effects. Take a look at Figure 7-1.

Tip

Because this chapter is about animation, most of the pages feature motion. You really must see these pages in your browser to get the effect, as a static screen shot can't really do any of these programs justice.

The general structure of this page provides a foundation ...

Get HTML, XHTML, and CSS All-In-One Desk Reference For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.