Javascript 初始化后是否向Swipe.JS添加幻灯片?
这是一个伟大的移动旋转木马脚本。是否有人找到在初始化后将幻灯片添加到旋转木马的方法?我的目标是在用户到达最后一张幻灯片时添加更多项目(类似于“无限旋转木马”) 下面是一个代码示例:Javascript 初始化后是否向Swipe.JS添加幻灯片?,javascript,Javascript,这是一个伟大的移动旋转木马脚本。是否有人找到在初始化后将幻灯片添加到旋转木马的方法?我的目标是在用户到达最后一张幻灯片时添加更多项目(类似于“无限旋转木马”) 下面是一个代码示例: this.collection.each(function(pic){ var slide = new PictureSlideView({model:pic}); this.$('.slide-container').append(slide.el); },this); this.$('.swip
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();
在检查脚本源代码时,我发现在添加新元素后调用
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();
你能提供一个jsfiddle和一个到carousel脚本的链接吗?在jsfiddle中复制我的设置很困难:我使用的是phonegap&backbone。以下是脚本链接:。您能提供一个JSFIDLE和一个到旋转木马脚本的链接吗?在JSFIDLE中复制我的设置很困难:我使用的是phonegap&backbone。下面是脚本链接:。现在看起来很明显,但是,如果他们在文档中提到这一点会更容易:现在看起来很明显,但是如果他们在文档中提到这一点会更容易: