javascript - 初始化后向 Swipe.JS 添加幻灯片?

标签 javascript

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

这是一个代码示例:

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/

相关文章:

javascript - 将数组中的值添加到对象 javascript

javascript - 为什么这个正则表达式不适用于 JavaScript?

javascript - 从外部或内部 div 动态加载内容到 div

javascript - 帮助反混淆此 JS 攻击

javascript - div 单击 anchor 标记下的 jquery 不起作用

javascript - 在浏览器的本地存储中存储对磁盘上文件的引用

javascript - 我不明白这个错误 : dataobj is not a function

javascript - NodeJS 中的 ES6 : Arrow functions in object literal, 返回的 'this' 值是什么?

javascript - 如何禁用仅使用 ENTER 提交表单

javascript - 在 .change() 处理程序之后通过 .load() 重新加载表时,JQuery 丢失初始单击事件