npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

spring-input

v2.0.0

Published

integrates scroll and flick physics

Downloads

5

Readme

spring-input

stable

A utility to provide a springy mouse and touch input, similar to bouncy scroll panels in iOS. This can be used in a variety of applications, such as scrolling, rotating a 3D camera, flicking a 2D card, etc.

Demo:

http://mattdesl.github.io/spring-input/

Adapted from touch-scroll-physics, which is more application-specific than this module.

Install

npm install spring-input --save

Example

See test.js for a full example.

var createSpring = require('spring-input')

// e.g. a slider along the x-axis
var spring = createSpring({
  min: 0,        // min bound
  max: 1,        // max bound
  edge: 0.1,     // gutter size
  value: 0.5,    // initial value
  damping: 0.25, // flick friction
  spring: 0.15   // "bounce back" friction
})

function onDragStart (x, y) {
  spring.start(x)
}

function onDragMove (x, y) {
  spring.move(x)
}

function onDragEnd (x, y) {
  spring.end(x)
}

function onRequestAnimationFrame () {
  spring.update()
}

This is a low-level module, intended to be used with your own input handling and update loop. This can be easily combined with the following modules:

  • touches - unified mouse / touch input and drag events
  • mouse-wheel - cross-browser mouse wheel events
  • raf-loop - a simple requestAnimationFrame loop

Usage

NPM

spring = createSpring([opt])

Creates a new sprint input with the optional settings:

  • value - the initial value, default 0
  • min - the minimum bound, default 0 (can be -Infinity)
  • max - the maximum bound, default 1 (can be Infinity)
  • edge - the relative edge gutter size, default 0 (i.e. no "bounce back")
  • damping - adjusts the friction when flicking; defualt 0.3
  • spring - adjusts the friction when bouncing back; default 0.2
  • maxVelocity - the maximum velocity in a flick, default 0.05

All values can be changed during runtime, eg:

spring.max = newScrollHeight

spring.start(value)

Called to trigger a "start" event with the specified value, such as the initial X mouse position.

spring.move(value)

Called to trigger a "move" event with the specified value, such as a new mouse X position.

spring.end()

Stops user input, allowing the value to be integrated and slide into place.

spring.update()

Integrates the spring. Should be called once per animation loop.

spring.value

The currently integrated value.

spring.velocity

The current velocity.

See Also

License

MIT, see LICENSE.md for details.