没有任何内置代码可以删除幻灯片,因此您可以使用上面的代码,或者如果您真的只想删除所有幻灯片,请执行此操作(无需避免删除克隆的幻灯片):
$('#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();
}
});