View Full Version : clearinterval on onmouseout for a slideshow.

11-12-2010, 05:53 AM
I am trying to have a slide show of pictures that are randomly generated stop when the user mouses over the image, I have got everything to work so far except the onmouseover event, even the onmouseout seems to work I don't necessarily need the exact answer but any guidance would be appreciated!

<script type="text/javascript">
/* ! [CDATA[ */
setInterval('randomImage()', 4000); //sets the interval of images to show every 4 seconds and runs the function to do so.

var imgs = new Array("outdoors.jpg", "kayak.jpg", "fishing.jpg", "scuba.jpg", "biking.jpg"); //the array of images

function randomImage() {
document.getElementById("image").src = imgs[Math.floor(Math.random()*imgs.length)];
//the function calls for a random number and applies it to the array of images to show a random picture.
/* ]]> */
<img src="outdoors.jpg" width="200" height="200" alt="Random Image" id="image" onmouseover="clearInterval();" onmouseout="randomImage()" />

I am not quite sure what I am doing wrong I've tried mutliple different set ups for the "onmouseover="clearInterval();" and nothing seems to work.

11-12-2010, 06:18 AM
I figured it out, actually a rather simple fix after I looked at it just set the interval to a variable. Thanks anyway codingforums ;P