0

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

这是一个代码示例:

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:
// ...
4

1 回答 1

6

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();
于 2013-06-13T12:52:53.380 回答