Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export default function() {
touchending,
touchDelay = 500,
wheelDelay = 150,
clickDistance2 = 0;
clickDistance2 = 0,
touchScroll = false;

function zoom(selection) {
selection
Expand All @@ -76,7 +77,6 @@ export default function() {
.on("touchstart.zoom", touchstarted)
.on("touchmove.zoom", touchmoved)
.on("touchend.zoom touchcancel.zoom", touchended)
.style("touch-action", "none")

@spetex spetex Aug 27, 2019

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have not found the reason for this class. It unfortunately prevents natural page scroll to apply. We can probably programatically add and remove the class during the touchmove if it is necessary.

.style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
}

Expand Down Expand Up @@ -321,7 +321,6 @@ export default function() {
touches = event.changedTouches,
n = touches.length, i, t, p, l;

noevent();
if (touchstarting) touchstarting = clearTimeout(touchstarting);
g.taps = 0;
for (i = 0; i < n; ++i) {
Expand All @@ -341,14 +340,24 @@ export default function() {
}
else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
else return;
g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));

var move = constrain(translate(t, p, l), g.extent, translateExtent);

if ((move.x != 0 || move.y != 0) && !touchScroll) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

touchScroll we need to prevent the noevent() when you are already scrolling the page, the browser ingores it anyways

noevent();
g.zoom("touch", move);
} else {
touchScroll = true;
}
}

function touchended() {
if (!this.__zooming) return;
var g = gesture(this, arguments),
touches = event.changedTouches,
n = touches.length, i, t;

touchScroll = false;

nopropagation();
if (touchending) clearTimeout(touchending);
Expand Down