Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery randomly fadeIn images

I have a container with a lot of small images.

<div id="container">
   <img src="1.jpg" />
   <img src="2.jpg" />
   <img src="3.jpg" />
   ...
   <img src="100.jpg" />
</div>

I set opacity to 0. (not hidding) Then I want to show(fadeIn) random image after half second. for example 5th, 1st, 55th ...

Any suggestions, thanx a lot

like image 789
noname Avatar asked Jun 18 '09 12:06

noname


1 Answers

try this

<script type="text/javascript">

//generate random number
var randomnumber=Math.floor(Math.random()*$("#container").children().length);
$(function() {
    //hide all the images (if not already done)
    $("#container > img").hide();

    //set timeout for image to appear (set at 500ms)
    setTimeout(function(){
       //fade in the random index of the image collection
       $("#container > img:eq(" + randomnumber + ")").fadeIn();
    }, 500);       
});
</script>
like image 145
Josh Avatar answered Sep 19 '22 18:09

Josh