# impetus

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

Latest version **0.8.8** (published 2018-11-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install impetus
pnpm add impetus
yarn add impetus
bun add impetus
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.8.8 |
| Published | 2018-11-23 |
| First published | 2015-09-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 145.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 488 |
| Author | Chris Bateman |
| Maintainers | chrisbateman |
| Keywords | momentum, touch |

## Links

- npm: https://www.npmjs.com/package/impetus
- Repository: https://github.com/chrisbateman/impetus
- Homepage: http://chrisbateman.github.io/impetus/
- Issues: https://github.com/chrisbateman/impetus/issues
- npm.io page: https://npm.io/package/impetus

## Recent versions

- 0.8.8 (latest) — 2018-11-23
- 0.8.7 — 2017-06-10
- 0.8.6 — 2017-06-10
- 0.8.5 — 2017-06-09
- 0.8.4 — 2017-06-09
- 0.8.3 — 2015-09-29
- 0.8.1 — 2015-09-26

## README

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](http://chrisbateman.github.io/impetus).

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 ###
```javascript
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 ###
<table>
	<thead>
		<tr>
			<th></th>
			<th scope="col">Type</th>
			<th scope="col">Default</th>
			<th scope="col">Description</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<th scope="row" align="left"><code>source</code></th>
			<td><code>HTMLElement</code>|<code>String</code></td>
			<td>document</td>
			<td>Element reference or query string for the target on which to listen for movement.</td>
		</tr>
		<tr>
			<th scope="row" align="left"><code>update</code> (required)</th>
			<td><code>function(x, y)</code></td>
			<td>-</td>
			<td>This function will be called with the updated <var>x</var> and <var>y</var> values.</td>
		</tr>
		<tr>
			<th scope="row" align="left"><code>multiplier</code></th>
			<td><code>Number</code></td>
			<td><code>1</code></td>
			<td>The relationship between the input and output values.</td>
		</tr>
		<tr>
			<th scope="row" align="left"><code>friction</code></th>
			<td><code>Number</code></td>
			<td><code>0.92</code></td>
			<td>Rate at which values slow down after you let go.</td>
		</tr>
		<tr>
			<th scope="row" align="left"><code>initialValues</code></th>
			<td><code>[Number, Number]</code></td>
			<td><code>[0, 0]</code></td>
			<td>Array of initial <var>x</var> and <var>y</var> values.</td>
		</tr>
		<tr>
			<th scope="row" align="left"><code>boundX</code></th>
			<td><code>[Number, Number]</code></td>
			<td>-</td>
			<td>Array of low and high values. <var>x</var>-values will remain within these bounds.</td>
		</tr>
		<tr>
			<th scope="row" align="left"><code>boundY</code></th>
			<td><code>[Number, Number]</code></td>
			<td>-</td>
			<td>Array of low and high values. <var>y</var>-values will remain within these bounds.</td>
		</tr>
		<tr>
			<th scope="row" align="left"><code>bounce</code></th>
			<td><code>Boolean</code></td>
			<td><code>true</code></td>
			<td>Whether to stretch and rebound values when pulled outside the bounds.</td>
		</tr>
	</tbody>
</table>


### Methods ###
<table>
	<thead>
		<tr>
			<th></th>
			<th scope="col">Description</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<th scope="row" align="left"><code>.pause()</code></th>
			<td>Disable movement processing.</td>
		</tr>
		<tr>
			<th scope="row" align="left"><code>.resume()</code></th>
			<td>Re-enable movement processing.</td>
		</tr>
		<tr>
			<th scope="row" align="left"><code>.setMultiplier( &lt;number&gt; )</code></th>
			<td>Adjust the <var>multiplier</var> in flight.</td>
		</tr>
		<tr>
			<th scope="row" align="left"><code>.setValues( &lt;number&gt; , &lt;number&gt; )</code></th>
			<td>Adjust the current <var>x</var> and <var>y</var> output values.</td>
		</tr>
		<tr>
			<th scope="row" align="left"><code>.setBoundX( &lt;number[2]&gt; )</code></th>
			<td>Adjust the X bound</td>
		</tr>
		<tr>
			<th scope="row" align="left"><code>.setBoundY( &lt;number[2]&gt; )</code></th>
			<td>Adjust the Y bound</td>
		</tr>
		<tr>
			<th scope="row" align="left"><code>.destroy()</code></th>
			<td>
				This will remove the previous event listeners. Returns null so you can use it to destroy your variable if you wish, i.e. <code>instance = instance.destroy()</code>
			</td>
		</tr>
	</tbody>
</table>


### Browser Support ###
Chrome, Firefox, Safari, Opera, IE 9+, iOS, Android. Support for IE 8 can be achieved by adding a polyfill for `addEventListener`.

---
_Source: https://npm.io/package/impetus · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
