vue-carousel icon indicating copy to clipboard operation
vue-carousel copied to clipboard

Disable vertical scrolling when swiping on mobile

Open ja1shan opened this issue 7 years ago • 15 comments

Firstly, thank you for this Vue Componoent. It is working perfectly apart from one little issue I have.

When using it on a mobile device and swiping on the slider it can scroll the page up and down. Is there any way to prevent vertical scrolling on mobile when swiping left and right on the slider.

I tried to add e.preventDefault() on the onDrag function when (Math.abs(newOffsetX) > 5) with no luck.

Thanks

ja1shan avatar Nov 07 '18 05:11 ja1shan

Hey @ja1shan, just to confirm this is because the content of your slide is taller than the carousel? Can you send a fiddle or screen capture of this happening so we can properly diagnose?

quinnlangille avatar Nov 11 '18 12:11 quinnlangille

I'm not sure but my Carousel and Slider seems to be the same size. Here is an example https://jsfiddle.net/gvzn6mt3/5/

ja1shan avatar Nov 11 '18 23:11 ja1shan

Oh, I think I misunderstood. You want to disable vertical scrolling on the entire page when you're on mobile? This isn't related to the carousel, but you can probably use overflow: hidden or position: fixed. There's a pretty good thread on that here -> https://css-tricks.com/forums/topic/prevent-body-scrolling-when-the-user-scrolls-on-fixed-position-div/

quinnlangille avatar Nov 12 '18 21:11 quinnlangille

I only wanted to disable the scrolling when the user is swiping (through the carousel slides), not entirely. I did try use e.preventDefault() earlier with no luck.

It is fine, I will look into another solution.

An example would be https://surmon-china.github.io/vue-awesome-swiper/ When swiping the Carousel on mobile (you can't scroll up and down by swiping up and down).

ja1shan avatar Nov 13 '18 00:11 ja1shan

I am also looking for a solution for it. There are several ways to do it. I am trying to find the most basic one.

koraykupe avatar Dec 11 '18 15:12 koraykupe

@koraykupe feel free to share if you end up implementing something on your end!

quinnlangille avatar Mar 18 '19 02:03 quinnlangille

Sorry, I switched to another plugin.

koraykupe avatar Mar 18 '19 08:03 koraykupe

@koraykupe I've tried to do it but I did't find a solution. Could you share what plugin you're using?

mateo2181 avatar Jul 15 '19 09:07 mateo2181

I'm facing the same issue here ⚠️ I applied the following solution to solve:

<carousel
    @touchstart.native="onTouchStart"
    @touchend.native="onTouchEnd"
  >
</carousel>


onTouchStart() {
  document.querySelector('body').style.overflow = 'hidden';
},
onTouchEnd() {
  document.querySelector('body').style.overflow = 'auto';
},

notnotgabriel avatar Aug 13 '19 14:08 notnotgabriel

i have the same problem... @notnotgabriel somehow this doesnt work for me... :(

simonmaass avatar Nov 06 '19 16:11 simonmaass

I have a same issue. The advise of @notnotgabriel - not working :(

Can this issue include to roadmap?

StanZhuravlev avatar Nov 17 '19 16:11 StanZhuravlev

Yeah that would be awesome - with "mobile-first" approaches in most ux discussions nowadays that would be a great feature!

simonmaass avatar Nov 25 '19 08:11 simonmaass

Did anyone try adding touch-action: pan-x !important; to .VueCarousel-slide class? This should limit pan-y. Worked for me. It doesn't cure all bounce frustrations but solved this issue for me.

AleitaT avatar Dec 01 '19 21:12 AleitaT

@AleitaT problem is you cannot scroll at all then :) but should be good to go for now...

plugin support would be nice tho, similar to prop "prevent-y-scroll" from vueperslides: https://antoniandre.github.io/vueper-slides

mwager avatar Mar 06 '20 10:03 mwager

I used "touch-pan-y" in the tailwind and it worked fine.

keelviinn avatar May 02 '23 14:05 keelviinn