有没有办法随机化这个 jquery 幻灯片中的图像,这样每次页面刷新时它都不会以相同的图像开始?
这是HTML:
<div id="slideshow">
<img src="http://image.jpg" alt="image 1" class="active">
<img src="http://image.jpg" alt="image 2" >
<img src="http://image.jpg" alt="image 3" >
</div>
这是脚本:
function slideSwitch() {
var $active = $('#slideshow IMG.active');
if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
var $next = $active.next().length ? $active.next()
: $('#slideshow IMG:first');
$active.addClass('last-active');
$next.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 6000, function() {
$active.removeClass('active last-active');
});
}
$(function() {
setInterval( "slideSwitch()", 8000 );
});
谢谢!!!!