Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
|
I haven't done exactly what you're describing, but there's a couple of things you must understand in order to accomplish it. It should be noted that you can't fade background images, only IMG tags, or entire DIVs that have background-images on them. You can't just fade the background-image by itself.
1. To fade two images into another, they should be absolutely positioned in the same place. Either one is behind the other, which fades out, or else both fade in and out simultaneously (this is probably what you want if you don't know what order they'll be in).
2. You need to understand random numbers in JavaScript. Here is a guide I've found useful: Make JavaScript Math.random useful
Other than that, it is just a matter of hiding all of the images to begin with, revealing one randomly, placing a class on it to distinguish it, then choosing from the remaining items in the nodelist to determine which one to fade to. It is probably about an hour job to work out the problems...
Here's a snippet of code that may help you:
Code:
var images = $("#slide img:not(.active)");
var random = Math.floor(Math.random()*images.length);
$(images).eq(random).addClass("changeto");
This assumes that the image currently being displayed has a class of "active" on it, and the image being switched to gets a "changeto" class added to it. Of course, you actually have to do something with these two classes when you do your fade, then switch the active class in the callback, but that's another story...
Last edited by wayfarer07; 06-23-2009 at 08:51 PM..
|