• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 5. More Fun with Images > Displaying a Random Image

Displaying a Random Image

If your site is rich with graphics, or if you are displaying digital artwork, then you might want to have a random image from your collection appear when the user enters your site. Once again, JavaScript to the rescue! Script 5.7 is the answer, and Figure 5.11 shows the result of the script, in this case images of a stuffed lion, tiger, and bear (oh, my!).

Script 5.7. You can display random images on your page with this script, which uses JavaScript's Math.random method to generate a random number.



PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint