我有以下代码:
<script type="text/javascript">
var imgs = new Array("images/banner2.jpg", "images/banner3.jpg", "images/banner4.jpg");
var alt = new Array();
var bgcolor = new Array("#202020", "#00040F", "#202020");
var currentAd = 0;
var imgCt = 3;
function cycle() {
if (currentAd == imgCt) {
currentAd = 0;
}
var div = document.getElementById('banner_bar');
div.style.backgroundColor = bgcolor[currentAd]
var banner = document.getElementById('adBanner');
banner.src = imgs[currentAd]
banner.alt = alt[currentAd]
currentAd++;
}
window.setInterval("cycle()", 8000);
</script>
<div id="banner_bar">
<img class="banner" src="images/banner4.png" id="adBanner">
</div>
背景和图像更改效果很好,但我无法让淡入淡出工作。它要么破坏旋转器,要么什么都不做。关于如何通过重写轮换代码来做到这一点的任何想法?
编辑:我不知道我是否在正确的轨道上,但如果有人能把我推向正确的方向,我将不胜感激
<script type="text/javascript">
var imgs = new Array("images/banner2.jpg","images/banner3.jpg","images/banner4.jpg");
var alt = new Array();
var bgcolor = new Array("#FFF","#00040F","#000");
var currentAd = 0;
var imgCt = 3;
function cycle() {
if (currentAd == imgCt) {
currentAd = 0;
}
$("#banner_bar").fadeOut(3000, function () {
var div = document.getElementById('banner_bar');
div.style.backgroundColor=bgcolor[currentAd]
var banner = document.getElementById('adBanner');
banner.src=imgs[currentAd]
banner.alt=alt[currentAd]
currentAd++;
) };
}
window.setInterval("cycle()",5000);
</script>
<div id="banner_bar">
<img class="banner" src="images/banner4.jpg" id="adBanner">
</div>