You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have managed to make this work using this code (made it using Swiper React but overall it can be used for Swiper in general) :
<SwiperonInit={(swiper)=>{if(window?.innerWidth>769){letisSwiping=false;letnextSlide=swiper.activeIndex+1;letprevSlide=swiper.activeIndex-1||swiper.slides.length-1;swiper.el.addEventListener('wheel',(event)=>{event.preventDefault();if(isSwiping)return;// Only trigger slide on moderate deltaXif(Math.abs(event.deltaX)>10&&Math.abs(event.deltaX)<40&&isSwiping===false){isSwiping=true;if(event.deltaX>0&&nextSlide!=swiper.activeIndex){swiper.slideNext();return;}elseif(event.deltaX<0&&prevSlide!=swiper.activeIndex){swiper.slidePrev();return;}}},{passive: false},);swiper.on('transitionEnd',()=>{setTimeout(()=>{isSwiping=false;nextSlide=swiper.activeIndex+1;prevSlide=swiper.activeIndex-1;},100);});}// .... other code
WHY this method:
The stuff regarding the event listener is quite self explanatory, why i needed to use the prev and next slide is simply because if you where to make a long swipe the swiper would start acting crazy and swipe multiple slides. This is used to prevent it.
Sending it here because i thought someone would need it
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have managed to make this work using this code (made it using Swiper React but overall it can be used for Swiper in general) :
WHY this method:
The stuff regarding the event listener is quite self explanatory, why i needed to use the prev and next slide is simply because if you where to make a long swipe the swiper would start acting crazy and swipe multiple slides. This is used to prevent it.
Sending it here because i thought someone would need it
Beta Was this translation helpful? Give feedback.
All reactions