You can use javascript's Math.random() function. I'll show you an example of how you can do it by storing your images in an array, and later randomly picking one of the images.
Say you have:
HTML Code:
<img id="hover" src="something.png" onmouseover="randomHover();" onmouseout="resetState();">
The following javascript should do the work:
Code:
function randomPick(arr) {
var selected = arr[Math.floor(Math.random()*arr.length)]
return selected;
}
images =
[
"image1.png",
"image2.png",
"image3.png",
"image4.png",
"image5.png"
]
function randomHover () {
var myImage = document.getElementById('hover');
var selImage = randomPick(images);
myImage.src = selImage;
}
function resetState() {
var myImage = document.getElementById('hover');
myImage.src = "something.png";
}
Bookmarks