0

It appears that when you are using overflow: hidden on Edge the event mousewheel no longer gets triggered when you use the touch-pad to scroll (middle button of mouse still works). This problem only appears when using Edge and Internet Explorer.

The following script logs the scrolling distances that should occur with each mousewheel event. (Works when using chrome and firefox).

document.querySelector("#out").addEventListener("mousewheel", function(event) {
  if (event.defaultPrevented) return;
  if (event.shiftKey) {
    if (event.deltaX || event.deltaY) {
      move(0, event.deltaX || event.deltaY);
      event.preventDefault();
    }
    return;
  }
  console.log(event.deltaY, event.deltaX);
  event.preventDefault();
}, {
  passive: false
});
#out {
  width: 200px;
  height: 200px;
  overflow: hidden;
}
<div id="out">
  <div id="in">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec facilisis tortor ultricies nibh mollis scelerisque. Proin eget mauris sollicitudin, eleifend lorem nec, aliquam justo. Pellentesque commodo ante nec finibus porta. Nam lobortis tempus ultrices. Ut ultrices, enim eget sodales eleifend, enim ipsum tincidunt nisl, ut tempor justo ante non nisi. Etiam ut ex non justo pellentesque posuere. Nulla sollicitudin massa viverra sapien congue, quis faucibus nisl aliquam. Duis ac fringilla eros. Vestibulum pretium, sem pulvinar consectetur ornare, urna justo vestibulum ligula, ullamcorper dignissim lectus velit quis turpis. Proin eu risus justo. Sed at nibh ac tortor rutrum mollis sagittis bibendum leo. Nunc feugiat mauris nec volutpat vestibulum. Phasellus ultricies, lacus sit amet posuere dapibus, nibh ligula pellentesque ligula, vitae congue massa ipsum sit amet velit. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris vel aliquet enim. Donec in lorem consequat, ullamcorper lectus sed, consectetur augue.
  </div>
</div>
nick zoum
  • 7,216
  • 7
  • 36
  • 80

1 Answers1

1

It's a known issue that you could find here. From the response of the Microsoft Edge Team in the issue tracker, we could see that the issue has been solved now by implementing PTP Pointer Events as outlined in this blog post.

You could use the Pointer Events like below:

In HTML, add the touch-action CSS property to your target element to prevent the browser from executing its default touch behavior in response to gestures:

<canvas height=400 width=400 id="canvas" style="touch-action: none;"></canvas>

In JavaScript, attach a Pointer Event listener to your target element. You can determine the type of pointer that caused the handler to be invoked using the pointerType property of the event object passed into the event listener callback:

document.getElementById('canvas').addEventListener('pointermove', function(event) {
    console.log('pointermove!');
});

For more information about Pointer Events, you could refer to this doc.

Yu Zhou
  • 11,532
  • 1
  • 8
  • 22
  • Isn't there a way keep the `touch-action: pinch-zoom` functionality for touch screens, will also overriding the scroll? – nick zoum Oct 17 '19 at 06:20
  • It seems that we only need to set the `touch-action` CSS property to `none` or other value than `auto`. If setting to `none`, you're telling the browser to not perform those browser-level actions on the element and instead trigger Pointer Events. Other values will allow you to continue some browser behaviors and then fire a subset of events. – Yu Zhou Oct 17 '19 at 07:26
  • I already had it set to `touch-action: pinch-zoom` since I wanted the `zoom-in` and `zoom-out` functionality. But the `pointermove` event wasn't getting fired. – nick zoum Oct 17 '19 at 07:31
  • You could try to set `touch-action: none` and refer to [this article](https://developer.mozilla.org/en-US/docs/Web/API/Pointer_events/Pinch_zoom_gestures) about using Pointer Events to detecting pinch and zoom gesture. You could also refer to [this thread](https://stackoverflow.com/questions/48124372/pointermove-event-not-working-with-touch-why-not/48254578#48254578) about `pointermove` not fired issue. – Yu Zhou Oct 17 '19 at 08:01
  • Even if I use `touch-action: none` and ignore the `zoom-in` and `zoom-out` functionality. There's still no way of getting the `deltaY` and `deltaX` values. – nick zoum Oct 17 '19 at 14:59
  • `deltaX` and `deltaY` is **WheelEvent** property, you can't get them in Pointer Events. [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent) has its own properties and inherits properties from [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent). You should choose the properties you need from them. Besides, I also find [this article](https://mobiforge.com/design-development/html5-pointer-events-api-combining-touch-mouse-and-pen) helpful, you could also check it. – Yu Zhou Oct 18 '19 at 02:29
  • By `deltaX` and `deltaY` I mean the distances traveled on the x and y axis, but I can't know them, without knowing the coordinates of the start event. Is there a way to calculate them using `PointerEvent`? – nick zoum Oct 18 '19 at 04:40
  • I think there's not such a property equal to the `deltaX` or `deltaY` as the movement of fingers in a touch-pad is different from the mouse wheel. If you want to calculate the scroll distance, I think you could get the `screenX` and `screenY` when `pointerdown` fired and get the properties again when `pointerup` fired, then calculate the difference between them. This is my assumption and you could have a try if you think it make sense. – Yu Zhou Oct 18 '19 at 09:03
  • Wasn't aware of the existence of those events. This should fix my problem, thank you. – nick zoum Oct 18 '19 at 10:49