<!-- This example is from the book _JavaScript: The Definitive Guide_. --> <!-- Written by David Flanagan. Copyright (c) 1996 O'Reilly & Associates. --> <!-- This example is provided WITHOUT WARRANTY either expressed or implied.--> <!-- You may study, use, modify, and distribute it for any purpose. --> <!-- The image that will be animated. Give it a name for convenience --> <IMG SRC="images/0.gif" NAME=animation> <SCRIPT> var frame =index.html 0; // keep track of what frame of the animation we're on. var timeout_id = null; // allows us to stop the animation. function animate() // The function that does the animation. { document.animation.src = images[frame].src; frame = (frame + 1)%10; timeout_id = setTimeout("animate()", 250); // display next frame later } // Count how many images have been loaded. When we reach 10, start animating function count_images() { if (++num_loaded_images == 10) animate(); } var num_loaded_images = 0; // Create the off-screen images and assign the image URLs. // Also assign an event handler so we can count how many images have been // loaded. Note that we assign the handler before the URL, because otherwise // the image might finish loading (if it is already cached, e.g.) before // we assign the handler, and then we'll lose count of how many have loaded! images = new Array(10); for(var i = 0; i < 10; i++) { images[i] =index.html new Image(); // Create an Image object images[i].onload = count_images; // assign the event handler images[i].src = "images/" + i + ".gif"; // tell it what URL to load } </SCRIPT> <!-- Buttons to control the animation. Note that we don't let the user -- start the animation before all the images are loaded --> <FORM> <INPUT TYPE=button VALUE="Start" onClick="if (!timeout_id && num_loaded_images==10) animate()"> <INPUT TYPE=button VALUE="Stop" onClick="if (timeout_id) clearTimeout(timeout_id); timeout_id=null;"> </FORM>
file: /Techref/language/java/script/definitive/examples/16.2.txt, 2KB, , updated: 1997/4/4 11:59, local time: 2024/8/22 22:15,
18.219.40.12:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://piclist.com/tecHREF/language/java/script/definitive/examples/16.2.txt"> language java script definitive examples 16</A> |
Did you find what you needed? |
![]() o List host: MIT, Site host massmind.org, Top posters @none found - Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr. |
The Backwoods Guide to Computer Lingo |
.