3

Dragging with hammer.js works on browser on pc. It fires continuously but when it comes to iPad, there is little problem. It fires after dragging/swiping finger stops on screen

template

<v-sheet v-pan="onPan">
    <div class="vista__img" ref="image" :style="{ backgroundImage: 'url(' + vista.image + ')' }"></div>
</v-sheet>

directives

 directives:{
    pan: {
      bind: function(el, binding) {
        if (typeof binding.value === "function") {
          const mc = new Hammer(el);
          mc.get("pan").set({ direction: Hammer.DIRECTION_ALL });
          mc.on("pan", binding.value);
        }
      }
    },

methods && computed

 methods:{
   onPan(e) {
      
      const dragOffset = -100 / this.itemWidth * e.deltaX / this.overflowRatio;
      const transform = this.currentOffset + dragOffset;
    
      this.$refs.image.style.setProperty("--x", transform);
    
      if (e.isFinal) {
        this.currentOffset = transform;
        const maxScroll = 100 - this.overflowRatio * 100;
        let finalOffset = this.currentOffset;     
      }
    },
  }

  computed: {
    overflowRatio() {
            return this.$refs.image.scrollWidth / this.$refs.image.offsetWidth;
        },
        itemWidth() {
            return this.$refs.image.scrollWidth;
    },
  },

Any idea about handling drag continuously on iPad?

AND this problem only occurs on iPad browsers(safari, chrome), there is no problem on iPhone

6
  • 1
    what does this "It fires finger drag is stop" mean
    – canbax
    Commented Nov 4, 2020 at 8:57
  • 1
    For example when I start to swipe/drag an image, and it doesn't fire 'till, dragging/swiping finger stop on screen. I am not sure how to explain it much more simpler... @canbax
    – firefly
    Commented Nov 4, 2020 at 9:10
  • 1
    If you are observing this on a real physical iPad device, then reproducing is hard. If it can be reproduced on the developer tools on the browser, it could be easier to debug. Also, a minimal reproducible sample might help.
    – canbax
    Commented Nov 4, 2020 at 9:15
  • Only ipad? Or any touch device?
    – Mosh Feu
    Commented Nov 4, 2020 at 9:22
  • no problem on Iphone/safari and macbook/chrome/safari too.. the problem occurs only IPAD @MoshFeu
    – firefly
    Commented Nov 4, 2020 at 9:29

1 Answer 1

0

Your issue can be related to a phenomenon called event propagation. iOS handles it a little bit differently than other systems (yes, it's system-specific, not browser-specific and Peter-Paul Koch wrote an article about it).

If you want to get a little bit of background, javascript.info has a great, extensive article about bubbling and capturing.

And if you just want to solve the problem, here's an issue on GitHub that should help. Also, hammer.js documentation mentions it as well.

Not the answer you're looking for? Browse other questions tagged or ask your own question.