mattdesl / spring-input Goto Github PK
View Code? Open in Web Editor NEWintegrates scroll and flick physics
License: MIT License
integrates scroll and flick physics
License: MIT License
to reproduce:
I just came across this package. Really useful!
But there is one behavior that's not expected in my opinion:
I call spring.start
in mousedown
, spring.move
in mousemove
, spring.end
in mouseup
and spring.update
in requestAnimationFrame
.
Now if I press the mouse button, then move the mouse really fast, then stop the mouse movement abruptly but hold the button pressed the spring.value
stops changing also, but if I now release the mouse button the spring.value
starts changing again because it has still a height velocity
value that is only being used while spring.interacting
is false
.
The reason is obviously because there is no mousestop
event in javascript that could be called if the mouse is not moving anymore.
My current solution is the following:
let framesSinceMove = 0;
function onDragMove(evt) {
framesSinceMove = 0;
spring.move(evt.clientX)
}
function onDragEnd(evt) {
spring.end(evt.clientX)
}
function tick() {
if(spring.interacting && ++framesSinceMove > 3) {
spring.velocity = 0
}
spring.update()
}
each time spring.update
is called I increment a counter. Each time the mouse is moved I reset the counter. Then if spring.interacting
is true
and update
has been called more than 3 times (ie the mouse has not been moved for 4 frames) I reset the velocity.
I would suggest to build this into the library itself. Would you accept a pull request?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.