Swiper Touch Events - Enable click but disable drag
Asked Answered
D

3

14

I am using Swiper 3.4.2 slider with thumbs as a pagination slider. And I need to disable drag on the pagination slider but to enable click events so the main slider can be changed by clicking on thumbs in the pagination slider.

    var galleryThumbs = new Swiper('.gallery-thumbs', {
        spaceBetween: 0,
        slidesPerView: 'auto',
        shortSwipes: false,
        slideToClickedSlide: true,
        preventClicksPropagation: false,
        preventClicks: false
    });

By setting simulateTouch to false, I am loosing the click touch event also.

Dever answered 22/5, 2017 at 14:47 Comment(0)
D
36

Setting the touchRatio: 0 will disable the drag touch event and leave the click touch event enabled

Update from v4

allowTouchMove: false,
Dever answered 22/5, 2017 at 14:47 Comment(1)
For some reason noSwiping and onlyExternal didn't work for me, but this did. Thanks.Resolve
M
12

From version 4.0, you can use:

allowTouchMove

If false, then the only way to switch the slide is use of external API functions like slidePrev or slideNext

Miocene answered 18/11, 2019 at 21:30 Comment(0)
O
2

You can alsow use touchRatio at breakpoints:

breakpoints: {
    600: {
        slidesPerView: 1,
        spaceBetweenSlides: 30,
        touchRatio: 1
    },
    768: {
        slidesPerView: 2,
        touchRatio: 0
    }
},
Occultism answered 5/10, 2020 at 16:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.