Solved

JavaScript Animation

Posted on 1997-10-14
1
353 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

815 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

11 Experts available now in Live!

Get 1:1 Help Now