我使用 javascript 和 JQuery 创建了这个幻灯片。我想在网页上多次使用它。我可以让两者都出现,但只有一个会循环浏览所有图片,然后重新开始。第二个只是循环然后结束。有人可以帮我写代码吗?我希望网页上的所有幻灯片不断循环。谢谢。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type"/>
<title></title>
<script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
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}, 1000, function() {
$active.removeClass('active last-active');
});
}
$(function() {
setInterval( "slideSwitch()", 5000 );
});
</script>
<style type="text/css">
#slideshow {
position:relative;
height:350px;
}
#slideshow IMG {
position:absolute;
top:0;
left:0;
z-index:8;
opacity:0.0;
}
#slideshow IMG.active {
z-index:10;
opacity:1.0;
}
#slideshow IMG.last-active {
z-index:9;
}
</style>
</head>
<div id="slideshow">
<img src="ocean.png" alt="Slideshow Image 1" class="active" />
<img src="ocean2.png" alt="Slideshow Image 2" />
<img src="ocean3.png" alt="Slideshow Image 3" />
</div>
<br />
<div id="slideshow">
<img src="flower.png" alt="Slideshow Image 1" class="active" />
<img src="flower2.png" alt="Slideshow Image 2" />
<img src="flower3.png" alt="Slideshow Image 3" />
</div>
</body>
</html>