这是一个很棒的移动设备轮播脚本。有没有人找到一种在初始化后将幻灯片添加到轮播的方法?我的目标是当用户到达最后一张幻灯片时添加更多项目(类似于“无限轮播”)。
这是一个代码示例:
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();
关于javascript - 初始化后向 Swipe.JS 添加幻灯片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17083224/