-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement momentum panning #280
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great concept! I took a quick look through the code and noticed some minor formatting issues.
In your demo, I notice some unexpected behavior:
- If I drag, then stop moving, then release the mouse, the momentum is way higher than I would expect
- If I drag, then stop moving, then release the mouse, I would expect that the momentum should be zero
Perhaps a time component is needed here, as in, when the drag starts, start monitoring the movement with a setInterval
or similar, then take the average motion over the last 3 intervals, or something like that.
src/zoom.js
Outdated
startX = x0; | ||
startY = y0; | ||
|
||
cancelMomentumTracking(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor formatting inconsistency
cancelMomentumTracking(); | |
cancelMomentumTracking(); |
@@ -387,7 +442,7 @@ export default function() { | |||
if (g.taps === 2) { | |||
t = pointer(t, this); | |||
if (Math.hypot(touchfirst[0] - t[0], touchfirst[1] - t[1]) < tapDistance) { | |||
var p = select(this).on("dblclick.zoom"); | |||
var p = select(this).on('dblclick.zoom'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var p = select(this).on('dblclick.zoom'); | |
var p = select(this).on("dblclick.zoom"); |
#67
Demo: https://jsfiddle.net/zmeeva/6urw1s9d/
Usage: