I saw recently on facebook how if you hover over an album in someone's images, it will "rollover" through random images within that album, in essence a mini-slideshow. How in the world do they do that? I've roamed the internet for a good two hours and can't seem to find a good explanation as to how it is done with more than two images (the static image and the rollover image). If anyone could point me in the right direction it would be greatly appreciated.
Multiple images (more than 2) with rollover
Page 1 of 16 Replies - 488 Views - Last Post: 20 November 2012 - 11:13 PM
Replies To: Multiple images (more than 2) with rollover
#2
Re: Multiple images (more than 2) with rollover
Posted 18 November 2012 - 07:58 PM
Just create an array of images and randomly select one on hover. Here's an old code I found awhile back that should work:
HTML
Javascript
HTML
<img id="hover" src="two.png" onmouseover="onHover();" onmouseout="resetState();">
Javascript
function randomSelect(arr) {
var selected = arr[Math.floor(Math.random()*arr.length)]
return selected;
}
images =
[
"image1.png",
"image2.png",
"image3.png",
"image4.png"
]
function onHover () {
var myImage = document.getElementById('hover');
var selImage = randomSelect(images);
myImage.src = selImage;
}
function resetState() {
var myImage = document.getElementById('hover');
myImage.src = "something.png";
}
This post has been edited by IJET: 18 November 2012 - 08:04 PM
#3
Re: Multiple images (more than 2) with rollover
Posted 19 November 2012 - 03:57 AM
Well, the thing is, when you hover, it doesn't just rollover to just one image. After about 1-2 seconds it changes again to another image, and continues until you no longer hover your mouse over the image, after which it reverts to the original image...if that makes sense. I've had little issue finding little snippets and tutorials on rollovers and transitions and such, but I've not been able to learn more about this "mini-slideshow" thingamajig.
#4
Re: Multiple images (more than 2) with rollover
Posted 20 November 2012 - 01:20 AM
#5
Re: Multiple images (more than 2) with rollover
Posted 20 November 2012 - 03:41 PM
#6
Re: Multiple images (more than 2) with rollover
Posted 20 November 2012 - 08:04 PM
So I got it working with my images (randomly selects a handful to display), however I seem to have a problem in the loop. Whenever it gets to the last image it seems to pause for twice as long as the interval was set to. Is there a way to remedy this?
#7
Re: Multiple images (more than 2) with rollover
Posted 20 November 2012 - 11:13 PM
here's the updated fiddle
http://jsfiddle.net/...7soni/tQsZ5/11/
if you still find any problem.. let me know.. i'll try to solve it...
Happy Coding
/>
http://jsfiddle.net/...7soni/tQsZ5/11/
if you still find any problem.. let me know.. i'll try to solve it...
Happy Coding
This post has been edited by amit.soni: 20 November 2012 - 11:14 PM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote






|