0

这很简单,我敢肯定,但目前对我来说太复杂了。

Swipe.js,一个移动滑块,在每张幻灯片上都提供了很多很好的信息,以及可以在幻灯片期间和结束时执行的两个功能,但是我很难编写一些简单的逻辑来检测是否用户正在滚动到下一张幻灯片或上一张:

Swipe.js: https ://github.com/bradbirdsall/Swipe

可用功能:

window.mySwipe = new Swipe(document.getElementById('slider'), {
  callback: function(index, elem) {},
  transitionEnd: function(index, elem) {}
});

Swipe 的简单 API

Swipe API
Swipe exposes a few functions that can be useful for script control of your slider.

prev() slide to prev

next() slide to next

getPos() returns current slide index position

getNumSlides() returns the total amount of slides

slide(index, duration) slide to set index position (duration: speed of transition in milliseconds)
4

2 回答 2

2

像这样的东西可以让你到达那里。您只想在生产中的一个回调函数中执行此操作,但我不确定哪个确切给出了您刚刚转换到的幻灯片的索引,所以我为您输入了两个。

var sliderIndex = 0;
window.mySwipe = new Swipe(document.getElementById('slider'), {
  callback: function(index, elem) {
      if (index < sliderIndex) {
         //backwards 
      }else{
         //forwards
      }
      sliderIndex = index;
  },
  transitionEnd: function(index, elem) {
      if (index < sliderIndex) {
         //backwards 
      }else{
         //forwards
      }
      sliderIndex = index;
  }
});
于 2013-04-04T18:43:22.280 回答
0

检查 slideNextTransitionStart、slideNextTransitionEnd、slidePrevTransitionStart、slidePrevTransitionEnd 的 API 文档

于 2018-11-27T00:26:18.367 回答