沒有任何內置代碼可以刪除幻燈片,因此您可以使用上面的代碼,或者如果您確實想要刪除所有幻燈片,請執行以下操作(無需避免刪除克隆的幻燈片):
$('#slider li').remove();
然後在你想要的任何新的幻燈片添加(排序或其他)
$('<li>New Stuff</li>').appendTo('#slider');
然後更新滑塊
$('#slider').anythingSlider(); // don't include options
上述代碼基本上與AnythingSlider demo page(主題選擇器旁邊的按鈕)上的代碼相同。我在下面加入了更多評論:)
// 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();
}
});