0

スライドショーのカウンターを生成し、カウンターで画像と対応する番号の色を変更するはずのこのコードがあります。ただし、スライドショーが 2 回循環する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それを変更しましたが、それでもキューで発生します。何か案は?

4

2 に答える 2

0

showNews関数が実行されていないためだと思います。JavaScriptエンジンが評価していると思います

(function showNews(elem){
    //...
})

( $(".news:first"));

意図したとおり$(".news:first")にパラメーターとして渡すのではなく、2 つの異なる式として。JS では行末はオプションであるため、結果が有効な JavaScript である場合、パーサーは行末を自動的に挿入しますshowNews;この場合、関数を定義しますが、それを呼び出すことはなく、jQuery シーケンスを構築しますが、それを使用することはありません。

2 つの間のキャリッジ リターンを削除してみてください。

(function showNews(elem){
    //...
})($(".news:first"));
于 2013-05-29T21:50:06.577 に答える