你已經使用了幻燈片的代碼是太多了。這可以做得簡單得多。看看幻燈片的這個例子與隨機圖像:http://jsbin.com/iledo3/3
粘貼在這裏以供參考代碼:
<!doctype html>
<html>
<head>
<title></title>
<style type="text/css">
#slideshow-container { height:90px; position:relative; }
#slideshow-container img { position:absolute; left:0; top:0; width:100%; height:100% }
#slideshow { position:absolute; left:0; top:0; width:100%; height:100%; list-style:none }
#slideshow img { width:120px; height:90px; background-repeat:none; background-position:top left; position:absolute; left:0; top:0 }
#slideshow { position:absolute; left:0; top:0; width:100%; height:100%; }
#slideshow img { width:120px; height:90px; background-repeat:none; background-position:top left; position:absolute; left:0; top:0 } /* adjust this for your images */
</style>
</head>
<body>
<div id="slideshow-container">
<div id="slideshow">
<img src="http://dummyimage.com/120x90/f00/fff.png&text=Image+1">
<img src="http://dummyimage.com/120x90/0f0/fff.png&text=Image+2">
<img src="http://dummyimage.com/120x90/00f/fff.png&text=Image+3">
<img src="http://dummyimage.com/120x90/ff0/000.png&text=Image+4">
<img src="http://dummyimage.com/120x90/0ff/fff.png&text=Image+5">
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
//extending jQuery with ':random' selector, best put into separate plugin js file
jQuery.jQueryRandom = 0;
jQuery.extend(jQuery.expr[":"],
{
random: function(a, i, m, r) {
if (i == 0) {
jQuery.jQueryRandom = Math.floor(Math.random() * r.length);
};
return i == jQuery.jQueryRandom;
}
});
//end :random extend
$(function() {
$('#slideshow img').not(':random').hide(); //hide all images except one initially
setInterval(function(){
$('#slideshow img:visible').fadeOut('slow')
.siblings('img:random').fadeIn('slow') //find a random image
.end().appendTo('#slideshow');},
2000); //2 second interval
});
</script>
</body>
</html>
但我怎麼能實現它在幻燈片放映? – dbr 2011-01-27 05:47:07