我正在使用此代碼。當它改變圖像時,圖像淡出,然後另一圖像淡入,同時我可以看到背景顏色,這是我不想看到的。有沒有簡單的方法來淡化圖像,但在同一時間淡入下一個圖像,或另一種jQuery效果,如滑動圖像?我只是不想看到背景顏色。jQuery圖片淡入淡出效果
<script type="text/javascript">
$(document).ready(function(){
var imgArr = new Array(// relative paths of images
'css/images/main_img.jpg',
'css/images/main_img_2.jpg',
'css/images/main_img_3.jpg',
'css/images/main_img_4.jpg',
'css/images/main_img_5.jpg'
);
var preloadArr = new Array();
var i;
/* preload images */
for(i = 0; i < imgArr.length; i++){
preloadArr[i] = new Image();
preloadArr[i].src = imgArr[i];
}
var currImg = 1;
var intID = setInterval(changeImg, 6000);
//added this so that the first image is always the first from the array
$('#main_content').css('background','url(' + preloadArr[0].src +') top center no-repeat');
/* Main IMG */
function changeImg(){
$('#main_content').animate({opacity: 0}, 1000, function(){
$(this).css('background','url(' + preloadArr[currImg++%preloadArr.length].src +') top center no-repeat');
}).animate({opacity: 1}, 1000);
}
});
</script>
嘗試這樣的淡入淡出:http://www.simonbattersby.com/blog/simple-jquery-image-crossfade/ –
@JohnKoerner演示看起來整潔,我要試試看日Thnx – TooCooL