スライドを削除するコードは組み込まれていないため、上記のコードを使用できます。または、本当にすべてのスライドを削除したい場合は、次のようにします (複製されたスライドを削除する必要はありません)。
$('#slider li').remove();
次に、必要な新しいスライドを追加します (並べ替え済みなど)。
$('<li>New Stuff</li>').appendTo('#slider');
次に、スライダーを更新します
$('#slider').anythingSlider(); // don't include options
上記のコードは基本的に、AnythingSlider デモ ページ(テーマ セレクターの横のボタン) に表示されるコードと同じです。私はより多くのコメントでそれを以下に含めました:)
// Add a slide
var imageNumber = 1;
$('button.add').click(function(){
$('#slider1')
// add a new slide, but cycle between two images
.append('<li><img src="images/slide-tele-' + (++imageNumber%2 + 1) + '.jpg" alt="" /></li>')
// update the slider
.anythingSlider();
});
$('button.remove').click(function(){
// don't let the last slide get deleted - it's ok if you do delete it, it's just not purdy ;)
if ($('#slider1').data('AnythingSlider').pages > 1) {
// remove the last slide (the cloned slide is actually the last, that's why there is a ":not()" in there
$('#slider1 > li:not(.cloned):last').remove();
// update the slider
$('#slider1').anythingSlider();
}
});