Coder Social home page Coder Social logo

spring-input's People

Contributors

mattdesl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

spring-input's Issues

snaps to wrong place

to reproduce:

  1. place input at 0
  2. start dragging from far right of screen toward the left
  3. cursor will snap to the right edge

velocity keeps high if move fast, then not end

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.