初始化后将幻灯片添加到Swipe.JS中

Adding slides to Swipe.JS after initialization?

本文关键字:Swipe JS 添加 幻灯片 初始化      更新时间:2023-09-26

这是一个伟大的移动轮播脚本。有没有人找到一种方法来添加幻灯片到初始化后的旋转木马?我的目标是在用户到达最后一张幻灯片时添加更多项目(类似于"无限旋转木马")。

下面是一个代码示例:
this.collection.each(function(pic){
    var slide = new PictureSlideView({model:pic});
    this.$('.slide-container').append(slide.el);
},this);
this.$('.swipe').Swipe({
    continuous: false
});
// this doesn't work:
var newModel = new Picture({...});
var newSlide = new PictureSlideView({model:newModel});
this.$('.slide-container').append(slide.el);
// insert awesome code to fix it here:
// ...

检查脚本源,我发现在添加新元素后调用setup函数工作:

我的代码现在看起来像:
this.collection.each(function(pic){
    var slide = new PictureSlideView({model:pic});
    this.$('.slide-container').append(slide.el);
},this);
this.carousel = new Swipe(this.el.getElementsByClassName('swipe')[0], {
    continuous: false
});
// append new slide
var newModel = new Picture({...});
var newSlide = new PictureSlideView({model:newModel});
this.$('.slide-container').append(slide.el);
// run the setup again
this.carousel.setup();