前段时间做项目出现的问题
前提已引入swiper,此版本为原生js版,非jquery版
var swiper = new Swiper('.swiper-container', {
direction: 'vertical',
});Ï
var startScroll, touchStÏart, touchCurrent;
swiper.slides.on('touchstart', function (e) {
startScroll = this.scrollTop;
touchStart = e.targetTouches[0].pageY;
}, true);
swiper.slides.on('touchmove', function (e) {
touchCurrent = e.targetTouches[0].pageY;
var touchesDiff = touchCurrent - touchStart;
var slide = this;
var onlyScrolling =
(slide.scrollHeight > slide.offsetHeight) &&
(
(touchesDiff < 0 && startScroll === 0) ||
(touchesDiff > 0 && startScroll === (slide.scrollHeight - slide.offsetHeight)) ||
(startScroll > 0 && startScroll < (slide.scrollHeight - slide.offsetHeight))
);
if (onlyScrolling) {
e.stopPropagation();
}
}, true);
原理比较简单,主要是slide.scrollHeight > slide.offsetHeight判断实现