I have an image slider and I put them into a random order of output but i realized that one of the images keeps repeating. Is there any way to prevent repeating images with using Math.random()?
This is what I've done so far: http://jsfiddle.net/Y4jr6/
<script type="text/javascript" language="javascript">
//switch the landing page background images
function slideSwitch() {
//set variable active
var $active = $('#slideshow IMG.active');
//check if attribute active exists
if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
// use this to pull the images in the order they appear in the markup
var $next = $active.next().length ? $active.next()
: $('#slideshow IMG:first');
//throw images in random order
var $sibs = $active.siblings();
var rndNum = Math.floor(Math.random() * $sibs.length );
var $next = $( $sibs[rndNum] );
$active.addClass('last-active');
$next.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1000, function() {
$active.removeClass('active last-active');
});
}
$(function() {
setInterval( "slideSwitch()", 7000 );
});
</script>
Any help would be much appreciated!!