Need help with impetus?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

chrisbateman
445 Stars 72 Forks MIT License 71 Commits 31 Opened issues

Description

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

Services available

!
?

Need anything else?

Contributors list

# 62,670
Shell
CSS
PHP
Webpack
62 commits
# 505,094
i18n
JavaScr...
jQuery
HTML
1 commit
# 595,657
JavaScr...
1 commit
# 535,024
JavaScr...
1 commit
# 303,731
C
Shell
Objecti...
Apache ...
1 commit
# 24,684
unix
python-...
testing...
unittes...
1 commit

Impetus.js

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.

Impetus 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.

Usage

var myImpetus = new Impetus({
    source: myNode,
    update: function(x, y) {
        // 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.

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

Constructor Options

Type Default Description
source HTMLElement|String document Element reference or query string for the target on which to listen for movement.
update (required) function(x, y) - This function will be called with the updated x and y values.
multiplier Number 1 The relationship between the input and output values.
friction Number 0.92 Rate 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.
bounce Boolean true Whether to stretch and rebound values when pulled outside the bounds.

Methods

Description
.pause() Disable movement processing.
.resume() Re-enable movement processing.
.setMultiplier( <number> ) Adjust the multiplier in flight.
.setValues( <number> , <number> ) Adjust the current x and y output values.
.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
.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.