vuejs / vue-touch

Hammer.js wrapper for Vue.js
MIT License
2.72k stars 391 forks source link

Vue-touch with lateral swipe prevents vertical scrolling #81

Open pmioni opened 7 years ago

pmioni commented 7 years ago

Hi, I have included Vue-touch 2.0.0-beta.4 in a Vue 2 project. Code looks like this: `<v-touch tag="div" v-on:swiperight="prev" v-on:swipeleft="next" v-bind:swipe-options="{threshold: 70}" class="modelgalleryimages" :class="{ 'loading-background-gallery' : loading || imageLoading }">

</v-touch>`

It is an image gallery. Swiping laterally through the images works fine, but it prevents normal vertical scrolling when one tries to drag on the image. It seems that the underlying Hammer.js library has the same problem, and I haven't find a clear solution to it. I tried adding touchAction: "auto" to the options, as some suggested for Hammer.js, but it did not work. Could you please provide any suggestions / fixes?

admilne commented 7 years ago

I had a similar issue with the app I am building, although I had the opposite problem. Giving something the ability to scroll using overflow:scroll meant I could no longer swipe side to side. I got around it using v-on:panleft and v-on:panright instead. Perhaps that would work for you?

FPierre commented 7 years ago
VueTouch.config.swipe = {
  direction: 'horizontal'
}

fix the issue for me

pmioni commented 7 years ago

@FPierre , it works for me. Thank you very much. @yyx990803, it would be more streamlined to be able to pass this configuration directly in Vue.use() Would you accept a pull request?

LinusBorg commented 7 years ago

Sure, PRs are welcome.

gustavoquinalha commented 7 years ago

@FPierre thanks, this works for me

ghost commented 6 years ago

@FPierre Thanks, works like a charm.

This information should be in the frontpage of the plugin i think.

Cheers.

suprabhasupi commented 6 years ago

I was facing the same issue with pan. This solved my problem: VueTouch.config.pan = { direction: 'horizontal' } Please someone add in documentation as well.

Thanks.

liefswanson commented 6 years ago

Just as a note the proposed solutions set the configuration direction: 'horizontal' for every swipe in the entire application.

If you just wanted to disable hammer stealing your vertical swipes for a single element (say you put a v-touch on the root div of your App.vue so you could pop out a navbar?) you should configure direction on that element

<v-touch @swiperight='enableNav'
         @swipeleft='disableNav'
         :swipe-options="{
             direction: 'horizontal'
         }">

Doing this will allow direction: 'vertical' to still work globally in the case that you wanted it just for a few elements in your app, but not everywhere.

It may also work to do the inverse setting the swipe options individualy to allow direction: 'vertical', but I didn't try that.