Skip to content

Commit 5f6be19

Browse files
Use cartesian distance for pinch zoom gesture (mdn#42728)
* Use cartesian distance for pinch zoom gesture Pinch zoom gestures should use cartesian distance, because they are usually executed diagonally, and so that they can optionally be combined with a rotate gesture. * Break up long line Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 3f83ac3 commit 5f6be19

File tree

1 file changed

+5
-2
lines changed
  • files/en-us/web/api/pointer_events/pinch_zoom_gestures

1 file changed

+5
-2
lines changed

files/en-us/web/api/pointer_events/pinch_zoom_gestures/index.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ When this event is processed, the target's border is set to `dashed` to provide
8080

8181
```js
8282
function pointermoveHandler(ev) {
83-
// This function implements a 2-pointer horizontal pinch/zoom gesture.
83+
// This function implements a 2-pointer pinch/zoom gesture.
8484
//
8585
// If the distance between the two pointers has increased (zoom in),
8686
// the target element's background is changed to "pink" and if the
@@ -100,7 +100,10 @@ function pointermoveHandler(ev) {
100100
// If two pointers are down, check for pinch gestures
101101
if (evCache.length === 2) {
102102
// Calculate the distance between the two pointers
103-
const curDiff = Math.abs(evCache[0].clientX - evCache[1].clientX);
103+
const curDiff = Math.hypot(
104+
evCache[0].clientX - evCache[1].clientX,
105+
evCache[0].clientY - evCache[1].clientY,
106+
);
104107

105108
if (prevDiff > 0) {
106109
if (curDiff > prevDiff) {

0 commit comments

Comments
 (0)