防止PhotoSwipe幻灯片快速滑动/拖入

问题描述 投票:1回答:1

我似乎无法得到Photoswipe以防止拖/刷卡更改幻灯片(因此只有箭头转到上一个/下一个幻灯片)

问题是,我有一个内含触摸事件HTML幻灯片,但photoswipe的触摸事件,并取代它们,而在幻灯片的内容拖动周围,整个幻灯片过于移动...

我想应该这个事件来预防呢?

pswp.listen('preventDragEvent', function(e, isDown, preventObj) {
    preventObj.prevent = true;
});

我也试过“isClickableElement”选项,但似乎并没有帮助,要么...

javascript photoswipe
1个回答
0
投票

这种方法是不理想的,但如果你正在寻找禁用刷卡/,而不必使用PhotoSwipe的修改版本拖动,这个工作对我来说:

var allowSwipe = false;
function preventSwipe (e) {
    if (!allowSwipe) {
        e.preventDefault();
        e.stopPropagation();
    }
}

pswp.container.addEventListener('pointerdown', preventSwipe);
pswp.container.addEventListener('MSPointerDown', preventSwipe);
pswp.container.addEventListener('touchstart', preventSwipe);
pswp.container.addEventListener('mousedown', preventSwipe);

或者,如果你正在使用jQuery:

var allowSwipe = false;
$(pswp.container).on('pointerdown MSPointerDown touchstart mousedown', function () {
    return allowSwipe;
});

使用allowSwipe变量,你可以重新启用它设置为true,在任何时候刷卡。

© www.soinside.com 2019 - 2024. All rights reserved.