最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - pointer events vs touch and mouse events - Stack Overflow

programmeradmin1浏览0评论

I'm building an interface that should work with mouse or touch. My user may have difficulty hitting their desired target because of a variety of physical issues.

Pointer events seem perfect for this but I get different behavior.

I want to know when the pointer enters and leaves a target, as well as when it is down. Using the mouse if I press a mouse button over target T1 and move (while holding the button) to target T2 I get pointerover T1, pointerdown T1, pointerout T1, pointerover T2, pointerup T2. Just what I expect.

With a touch screen I get: pointerover T1, pointerdown T1, pointerup T1. No signal that I moved from one target to another.

How do I make touch behave more like the mouse?

This is on Chrome 99 on Linux Ubuntu.

I'm building an interface that should work with mouse or touch. My user may have difficulty hitting their desired target because of a variety of physical issues.

Pointer events seem perfect for this but I get different behavior.

I want to know when the pointer enters and leaves a target, as well as when it is down. Using the mouse if I press a mouse button over target T1 and move (while holding the button) to target T2 I get pointerover T1, pointerdown T1, pointerout T1, pointerover T2, pointerup T2. Just what I expect.

With a touch screen I get: pointerover T1, pointerdown T1, pointerup T1. No signal that I moved from one target to another.

How do I make touch behave more like the mouse?

This is on Chrome 99 on Linux Ubuntu.

Share Improve this question asked Mar 2, 2022 at 14:51 GaryBishopGaryBishop 3,7523 gold badges25 silver badges23 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 16

The answer is here call releasePointerCapture if the target has captured the pointer.

div.addEventListener('pointerdown', function(e) {
  if (e.target.hasPointerCapture(e.pointerId)) {
      e.target.releasePointerCapture(e.pointerId);
  }
}

Then touch behaves like the mouse.

发布评论

评论列表(0)

  1. 暂无评论