Solved

JavaScript Animation

Posted on 1997-10-14
1
340 Views
Last Modified: 2013-11-19
Hi there Can anybody help me.I am trying to make an animation of 10 Gifs using JavaScript with the animation starting on mouseover and stopping when the mouse is off . I tried everything I know (which isn't much) but I could not make it work.Can anyone post a script that will do that. Thanks!!!
0
Comment
Question by:albion
1 Comment
 
LVL 6

Accepted Solution

by:
Holger101497 earned 100 total points
ID: 1271315
Hi albion!
Here's a script that'll do it:
I also uploaded it to http://home1.gte.net/stratmhx/Animation/anim.html, just in case you want to see it "in action". It'll work fine in Netscape.
You can initialize as many images as you want in the anim-Array and the code will automatically play all of them (using the length-Attribute). Pathnames can be relative or absolute, just as they would be in the document.

<HTML>
<HEAD>
<TITLE>Animation-Demo</TITLE>
<script language="JavaScript">
  anim=new Array();  // preload Images for smooth Animation
  anim[0]=new Image(); anim[0].src="1.jpg";
  anim[1]=new Image(); anim[1].src="2.jpg";
  anim[2]=new Image(); anim[2].src="3.jpg";
  anim[3]=new Image(); anim[3].src="4.jpg";
  anim[4]=new Image(); anim[4].src="5.jpg";
  apos=0; //next Image to be used for animation

  function Anim() {
    document.images[0].src=anim[apos++].src;
    apos%=anim.length; //wrap at end
    AnimTimer=setTimeout("Anim()",300);
  }
</script>

</HEAD>

<BODY bgcolor=red>
<H1>  Hi there!</H1>
<H2> This is a short demo of the animation you were looking for...
<!-- if the link is supposed to lead somewhere, just remove the "return false", which stops Netscape from following the link -->
  <a href="javascript:void()" onclick="return false" onMouseOver="Anim()" onMouseOut="clearTimeout(AnimTimer)">
  <!-- need a link for mouseover!! -->
  <!-- clearTimeout stops the animation -->
    <img src="1.jpg" height=40 width=40 border=0></a>
<BR>
<H3>
Good luck and have fun!
</H3>
</BODY>
</HTML>

online at http://home1.gte.net/stratmhx/Animation/anim.html (for a limited time, so don't count on it in December!)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now