2012-04-18 15 views
0

こんにちは、私はJQueryスライドショーで作業しています。私のHTML内のすべての画像は互いに重なり合い、最後の画像からコードを始めるようにしました。しかし、それは動作しません、任意のアイデア?逆JQueryスライドショー

元のコードは次のようになります。

$(document).ready(function() { 
    var current = $('#gallery img:first'); 
    //Set the fade in effect for the next image, show class has higher z-index 
    current.addClass('show').css({ 
     opacity: 0.0 
    }).animate({ 
     opacity: 1.0 
    }, 1000); 

    setInterval('gallery()', 3000); 
}); 

function gallery() { 
    //if no IMGs have the show class, grab the first image 
    var current = ($('#gallery img.show') ? $('#gallery img.show') : $('#gallery img:first')); 

    //Get next image, if it reached the end of the slideshow, rotate it back to the first image 
    var next = ((current.next().length) ? current.next() : $('#gallery img:first')); 

    //Set the fade in effect for the next image, show class has higher z-index 
    next.css({ 
     opacity: 0.0 
    }).addClass('show').animate({ 
     opacity: 1.0 
    }, 1000); 

    //Hide the current image 
    current.animate({ 
     opacity: 0.0 
    }, 1000).removeClass('show'); 
}​ 

マイ逆のコードは次のようになります。テストページが存在しない場合には

$(document).ready(function() { 
    var current = $('#gallery img:last'); 
    //Set the fade in effect for the next image, show class has higher z-index 
    current.addClass('show').css({ 
     opacity: 0.0 
    }).animate({ 
     opacity: 1.0 
    }, 1000); 

    setInterval('gallery()', 3000); 
}); 

function gallery() { 
    //if no IMGs have the show class, grab the first image 
    var current = ($('#gallery img.show') ? $('#gallery img.show') : $('#gallery img:last')); 

    //Get next image, if it reached the end of the slideshow, rotate it back to the first image 
    var before = ((current.before().length) ? current.before() : $('#gallery img:last')); 

    //Set the fade in effect for the next image, show class has higher z-index 
    before.css({ 
     opacity: 0.0 
    }).addClass('show').animate({ 
     opacity: 1.0 
    }, 1000); 

    //Hide the current image 
    current.animate({ 
     opacity: 0.0 
    }, 1000).removeClass('show'); 
}​ 
+0

見たいテストページはありますか? – mprabhat

+0

@mprabhatのテストページはオンラインではありません、申し訳ありません –

+0

最後のアイテムだけが表示されていて、隠されていることはいつも起こっていますか?それはあなたの問題ですか? – mprabhat

答えて

1

、私はULの画像を追加これをした:

var before = ((current.prev().length) ? current.prev() : $('#gallery img:last')); 

これは、表示する画像を選択します。表示されない場合は、最後の画像を再度選択します。

これはうまくいきますか?

+0

は画像をulに入れませんでしたが、以前は追加されていました^^ –

+1

ああ、明示的になりたかった、とにかくそれがあなたを助けてうれしかった:) – mprabhat

関連する問題