Socket
Socket
Sign inDemoInstall

impulsion

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    impulsion

Add momentum to anything. It's like iScroll, except not for scrolling. Supports mouse and touch events.


Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Impulsion.js

npm version

Fork of the excellent impetus.js by Chris Bateman.

Adds new features such as:

  • Exposes previousX and previousY to our lifecycle events.
  • Adds more lifecycle events:
    • onStart: Called when starting to drag the element.
    • onStartDecelerating: Called when the deceleration begun.
    • onEndDecelerating: called when the deceleration has ended.

As well other bugfixes and minor features.

Add momentum to anything. It's like iScroll, except not for scrolling. Supports mouse and touch events.

Check out the demos on the home page.

Impulsion will probably never support anything other than simple momentum. If you need scrolling or touch carousels or anything like that, this probably isn't the tool you're looking for.

Installation

yarn add impulsion
# or npm install impulsion

Usage

import Impulsion from 'impulsion';
// const Impulsion = require('impulsion');

let myImpulsion = new Impulsion({
    source: myNode,
    onUpdate(x, y, previousX, previousY) {
        // whatever you want to do with the values
    }
});

You give it an area to listen to for touch or mouse events, and it gives you the x and y values with some momentum.

Impulsion will register itself as an AMD module if it's available.

Constructor Options

TypeDefaultDescription
sourceHTMLElement|StringwindowElement reference or query string for the target on which to listen for movement.
onStartfunction(x, y, px, py)-This function will be called when starting to drag the element. px and py are the previous x and y values.
onUpdate (required)function(x, y, px, py)-This function will be called with the updated x and y values. px and py are the previous x and y values.
onStartDeceleratingfunction(x, y, px, py)-This function will be called when the deceleration begun (and drag has ended). px and py are the previous x and y values.
onEndDeceleratingfunction(x, y, px, py)-This function will be called when the deceleration has ended. px and py are the previous x and y values.
multiplierNumber1The relationship between the input and output values.
frictionNumber0.92Rate at which values slow down after you let go.
initialValues[Number, Number][0, 0]Array of initial x and y values.
boundX[Number, Number]-Array of low and high values. x-values will remain within these bounds.
boundY[Number, Number]-Array of low and high values. y-values will remain within these bounds.
bounceBooleantrueWhether to stretch and rebound values when pulled outside the bounds.
windowHTMLElementwindowSpecify the root window element, only really needed when trying to applied Impulsion to child iframes.
addIosTouchmoveFixBooleantrueiOS sometimes fails to preventDefault when scrolling on the body. Per this comment, one fix is to add an empty touchmove listener to the main window. This library adds this by default, but if you want to override this hacky listener, it can be disabled by setting this option to false.

Other information:

Methods

Description
.pause()Disable movement processing.
.resume()Re-enable movement processing.
.forceUpdate()Call the onUpdate function manually. Can be used to update the scene after setValues() has been run.
.setMultiplier( <number> )Adjust the multiplier in flight.
.setValues( <number> , <number> , <number|null> , <number|null>)Adjust the current x, y, previousX and previousY output values. previousX and previousY can be null.
.setBoundX( <number[2]> )Adjust the X bound
.setBoundY( <number[2]> )Adjust the Y bound
.destroy() This will remove the previous event listeners. Returns null so you can use it to destroy your variable if you wish, i.e. instance = instance.destroy()

Browser Support

Chrome, Firefox, Safari, Opera, IE 9+, iOS, Android. Support for IE 8 can be achieved by adding a polyfill for addEventListener.

Keywords

FAQs

Last updated on 29 Sep 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc