Possible to disable touch simulation for slides but not scrollbar (idangerous swiper)?

旧城冷巷雨未停 提交于 2019-12-07 09:41:18

问题


I have an idangerous swiper on my page which successfully simulates touch events on both the slides and accompanying scrollbar (allowing a mouse click and movement to slide slides left or right).

This is fine, but I've now called draggable on the slides within the swiper, which means I need to stop this touch simulation (dragging the slides and moving them at the same time is causing confusion) - but only on the slides, not the scrollbar (I still need the scrollbar to function as it did subsequent to a mouse click and movement).

What I've Tried

According to the API I can disable touch simulation:

var swiper = new Swiper('.swiper', {
    slidesPerView: 3,
    simulateTouch: false,
    scrollbar: {
        container: '.swiper-scrollbar',
        hide: false,
        draggable: true,
        snapOnRelease: true
    }
});

This works as expected, but on both the scrollbar and slides, which is no good.

I've also tried returning false from a number of the events the swiper api exposes:

var swiper = new Swiper('.swiper', { slidesPerView: 3, onTouchStart: function() { return false; }, scrollbar: { container: '.swiper-scrollbar', hide: false, draggable: true, snapOnRelease: true } });

This doesn't have any effect at all.


回答1:


Here is solution for Swiper-3.3.1

simulateTouch:false



回答2:


I found a way that, for now, I'm happy with.

In the idangerous swiper source (idangerous.swiper-2.1.js) I return false from the onTouchStart function (line 1120) so my code now resembles the following:

    function onTouchStart(event) {
    if (params.preventLinks) _this.allowLinks = true;
    //Exit if slider is already was touched

    return false;

    if (_this.isTouched || params.onlyExternal) {
        return false;
    }

This is non-invasive to the way the scrollbar prototype works too, so the scrollbar's touch events are left in-tact.



来源:https://stackoverflow.com/questions/23780805/possible-to-disable-touch-simulation-for-slides-but-not-scrollbar-idangerous-sw

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!