How to prevent swiping on certain are of the slide using swiperjs
Asked Answered
A

3

9

We are using swiperjs for slide. It is working great but we have input inside the slide and it is very hard to fill up the input if users can actually swipe on those. Im wondering if there is a way to prevent the slider sliding if user touchstart on an input.

This is how we init the slider:

new Swiper('.slider', {
  resistance: true,
  resistanceRatio: 25,
});

The HTML inside the slides includes

<input type="text">
<input type='range' min='0' max='11'>
Astrogate answered 16/2, 2021 at 7:15 Comment(0)
A
14

I am answering this question in case somebody will have have the same issue in the future.

Just add the swiper-no-swiping class on the elements that are not swipable or change the noSwipingClass parameter.

Astrogate answered 16/2, 2021 at 7:54 Comment(1)
this solution works, but not disable the mouse wheel swipe...Murrhine
R
0

In ReactJS: Here you you can include the 'swiper-no-swiping' class to as explained by the first answer:

/*In ReactJS - this is how you would do it.*/
    <Swiper className='theSwiper' 
            slidesPerView={1.1}
            modules={[Autoplay, Pagination]}
            pagination={{ clickable: true }}
            watchSlidesProgress
            // onSlideChange={(e) => console.log(e)}
            // onReachEnd={() => { console.log("end game")}}
            >
        <SwiperSlide className='eachSlide swiper-no-swiping' >
            /*Place your slides contents*/
        </SwiperSlide>
    </Swiper>
Revolutionize answered 23/9, 2023 at 14:37 Comment(0)
R
0

I resolved the issue by adding the class name set in the noSwipingClass parameter (default is 'swiper-no-swiping') to the areas where I wanted to prevent swiping.

https://swiperjs.com/swiper-api#param-noSwipingClass

Rodrigo answered 14/5 at 0:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.