Image animation from a predefined array of images.

Hi,
I would like to know how could I create a page that contains an image .When a mouse moves over it , it's source keeps changing from a predefined array of images.
When the mouse moves out, its source returns to the first image of the array.

Thanks.
sherihan.
sherihanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cLFlaVACommented:
Hi sherihan.

Here's an example, is it what you're looking for?


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>
<head>
<title>Rotating Banner Example</title>

<script language="javascript" type="text/javascript">
<!--

var index = 0;
var cont = false;
var banners = new Array("http://experts-exchange.com/images/logoTopLeft.gif", "http://experts-exchange.com/images/certification.gif", "http://www.google.com/images/logo.gif");

function rotate() {
      if (cont) {
          if (index == banners.length) index = 0;
            document.getElementById('the_banner').src = banners[index];
            setTimeout('rotate()', 500);
            index++;
      }
}

function start() {
    cont = true;
      rotate();
}

function end() {
      cont = false;
      document.getElementById('the_banner').src = banners[0];
}

-->
</script>

<style type="text/css">

</style>

</head>

<body onload="">
<img id="the_banner" onmouseover="start();" onmouseout="end();" src="http://experts-exchange.com/images/logoTopLeft.gif" />
<br />
The banner above will change every 1/2 a second when you have the mouse over the image.
</body>

</html>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GwynforWebCommented:
<script >
var index = 0;
var frameSrc = new Array(
 "http://experts-exchange.com/images/indexLogoPerson_01.gif",
 "http://experts-exchange.com/images/indexLogoPerson_02.gif",
 "http://experts-exchange.com/images/indexLogoPerson_03.gif",
 "http://experts-exchange.com/images/indexLogoPerson_04.gif");

function preload(){
 frameArr=new Array
 for (i=0;i<frameSrc.length;i++)
 {frameArr[i]=new Image
  frameArr[i].src=frameSrc[i]
 }
}

function nextFrame() {
index++
document.getElementById('theFilm').src=frameArr[index%(frameArr.length)].src
}
</script>

<body onload="preload()">
<img id="theFilm" src="http://experts-exchange.com/images/indexLogoPerson_01.gif"
     onmouseover="index=0;timer=setInterval('nextFrame()',500)"
     onmouseout="clearInterval(timer);this.src=frameArr[0].src;index++">
</body>
0
GwynforWebCommented:
index++ in the  mouseout can be removed
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

GwynforWebCommented:
sherihan, Why have you accepted an answer that does not work?
0
GwynforWebCommented:
...in IE that is.
0
sherihanAuthor Commented:
hi GwyforWeb,
why do u say that the accepted coad doesn't work.
I tested it and it works correctly.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.