我有這樣的代碼應該爲幻燈片顯示生成一個計數器,然後在計數器中更改圖片和相應的數字顏色。但是,在幻燈片放映循環兩次之後,計數器更改爲display:none
,然後每次幻燈片放映開始時都重新出現並消失。幻燈片計數器消失
//icons for newsreel guide
for(i=0;i<document.getElementsByClassName("news").length;i++){
var count=i+1;
$('#counter').append('<span class="count">'+count+'</span>');
}
//newsreel script
$(".news").hide();
setTimeout (function() {
var wait = $(".news:last").index()*12000+12000;
function newsreel(){
var i=0;
(function showNews(elem){
if(i==document.getElementsByClassName("count").length){
i=0;
}
document.getElementsByClassName("count")[i].style.color="#000";
elem.fadeIn(2000,function(){
elem.delay(8000).fadeOut(2000,function(){
document.getElementsByClassName("count")[i].style.color="#3159a0";
i=i+1;
$(this).next().length && showNews($(this).next());
});
});
})
($(".news:first"));
setTimeout (arguments.callee, wait);
}/*end newsreel()*/
newsreel();
}, 2000);
起初我還以爲是使用過時的arguments.callee
,但我改變了這一切,它仍然發生在線索。有任何想法嗎?
爲什麼你會使用棄用的代碼? –
@Justin Morgan很久以前,有人幫我做了這個幻燈片,那是他們當時的建議。 – user2434247
那條線是幹什麼的? '$(this).next()。length && showNews($(this).next()); ' –