gpt4 book ai didi

javascript - Swipe.js - 简单检测用户的滚动方向(向后或向前?)

转载 作者:行者123 更新时间:2023-12-02 18:51:06 24 4
gpt4 key购买 nike

这很简单,我确信这一点,但目前对我来说太复杂了。

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

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)

最佳答案

这样的事情可以让你到达那里。您只想在生产中的回调函数之一中执行此操作,但我不确定哪个函数准确给出了您刚刚转换到的幻灯片的索引,因此我为您添加了这两个函数。

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;
}
});

关于javascript - Swipe.js - 简单检测用户的滚动方向(向后或向前?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15818773/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com