【问题标题】:Swiper slider. Prepeding one slide and simulating transition to it滑动滑块。准备一张幻灯片并模拟过渡到它
【发布时间】:2014-04-17 15:50:40
【问题描述】:

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

目前情况:

  • 开头只有一张幻灯片。

我想要每次点击按钮是:

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

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

提前致谢。

【问题讨论】:

    标签: javascript jquery slider swiper


    【解决方案1】:

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

    单击按钮(带有 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();
        }
    });
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-25
      • 2015-06-24
      • 1970-01-01
      • 1970-01-01
      • 2014-10-15
      • 1970-01-01
      • 2019-01-29
      • 2021-08-27
      相关资源
      最近更新 更多