SitePoint Enthusiast
I have a series of small pics that when you rollover, I would like them to be replaced with a new random one (and stay as the new image, until next rollover).
Any help much appreciated!
I don't know much about javascript, but i bet you just have to do something like OnMouseOver="javascript :randomscript()" .
Then in the < HEAD > section, put your random image javascript function (here called "randomscript").
Hope this helps
Here's one way to do it:
<html>
<head>
<title>Untitled</title>
<script language="JavaScript">
<!--
function randomImage() {
pic = new Array();
pic[0] = 'little_dude.gif';
pic[1] = 'grower.gif';
pic[2] = 'scrubz.gif';
randomNum = Math.floor(Math.random()*pic.length);
newImage = 'images/' + pic[randomNum];
return newImage;
}
// -->
</script>
</head>
<body>
<img name="myImage" src="images/little_dude.gif" onMouseOver="this.src = randomImage();"><br>
<img name="myImage2" src="images/grower.gif" onMouseOver="this.src = randomImage();"><br>
<img name="myImage3" src="images/scrubz.gif" onMouseOver="this.src = randomImage();"><br>
</body>
</html>
SitePoint Enthusiast
Doesn't seem to work
Thanks for the reply scrubz. I've tried as you suggested, but it doesn't seem to work. What do you think is wrong?
http://www.bigdeepblue.com/dev/domin...llovertest.htm
(all the paths to gifs are correct)
Thanks.
Change the second to the last line in the script...
newImage = 'images/' + pic[randomNum];
to
newImage = pic[randomNum];
The way it was written, it was assuming that images were always in an 'images' directory, but since you're defining the full path of your images...
pic[0] = '../testsite/smallpics/maracca2.jpg'; )
you don't need to point to an 'images' directory. Hope this works for you.
SitePoint Enthusiast
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks