0

我想通过这个很棒的 JS 滑块 ( Swiper ) 使用其完整的 API来实现特定的行为,但直到现在我都不走运......需要一些帮助:

现在的情况:

  • 一开始只有一张幻灯片。

每次单击按钮时我想要的是:

  • 在每种情况下,在第一张幻灯片之前动态创建新幻灯片 --> 简单的事情,使用 Swiper API 的 prepend() 方法:)
  • 但是(这就是问题所在)我希望最终用户有一种刚刚加载前一张幻灯片的感觉,即单击按钮并看到向左滑动过渡......

我想要这种“罕见”的行为,因为我的滑块必须显示数百张幻灯片,并且从一开始就一次加载所有幻灯片会导致页面加载速度非常慢,因为它必须下载数百张图像......

提前致谢。

4

1 回答 1

2

我终于让它工作了,像这样:

单击按钮(带有 class="prev")后:

$(document).on('click', '.prev', function() {

    // If it is the first slide...
    if (mySwiper.activeIndex == 0) {

        // Slide content
        var slide = '<p>New slide</p>';

        // Creation of the slide (it instantly moves to index 0 --> the new slide)
        mySwiper.prependSlide(slide);

        // And then instant (speed = 0) swipe to slide with index 1
        // (the one we were watching before creating the new...)
        mySwiper.swipeTo(1, 0, false);

        // Finally, we implement the visual transition to new slide (index 0)
        mySwiper.swipePrev();
    }
});

我希望它可以帮助某人。谢谢。

于 2014-04-18T10:32:19.940 回答