这是一款适合移动设备的精彩旋转木马脚本。有没有人找到一种方法在初始化后将幻灯片添加到轮播?我的目标是在用户到达最后一张幻灯片时添加更多项目(类似于无限轮播')。
这是一个代码示例:
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:
// ...
答案 0 :(得分: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();