Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/broadsw0rd/kinetica

Unprecedented kinetic engine
https://github.com/broadsw0rd/kinetica

drag-and-drop kinetic scroll swipe

Last synced: about 1 month ago
JSON representation

Unprecedented kinetic engine

Awesome Lists containing this project

README

        

Kinetica


Unprecedented kinetic engine.



NPM version


bitHound Overall Score


js-standard-style

## Table of Contents

- [Features](#features)
- [Dependencies](#dependencies)
- [Install](#install)
- [Usage](#usage)
- [Examples](#examples)
- [API](#api)
- [Development](#development)

## Features

- Designed with performance in mind
- Lightweight - [10.4 KB](https://github.com/broadsw0rd/kinetica/blob/master/dist/kinetic.min.js)
- Mobile friendly - supports mouse events, touch events and pointer events

## Dependencies

- [Vectory](https://www.npmjs.com/package/vectory)

## Install

Download [dev](https://rawgit.com/broadsw0rd/kinetica/master/dist/kinetic.js) or [prod](https://rawgit.com/broadsw0rd/kinetica/master/dist/kinetic.min.js) version and put it in your html

```html

```

## Usage

```js
// start the digest loop
requestAnimationFrame(function loop (t) {
Kinetic.notify(t)
requestAnimationFrame(loop)
})

// create kinetic instance
var kinetic = new Kinetic({
el: document.body,
Vector: Vector
})

// spawn it
Kinetic.spawn(kinetic)

// implement scroll
var $target = document.getElementById('container')

var position = new Vector(0, 0)

function scrollTo (position) {
$target.style.transform = `translateY(${position.y}px)`
}

function isValidScroll (position) {
return position.y <= 0 && position.y > -5000 + window.innerHeight
}

function scrollY (pointers) {
if (pointers.length === 1) {
var pointer = pointers[0]
var next = position.add(pointer.delta)
if (isValidScroll(next)) {
scrollTo(next)
position = next
}
}
}

// subscribe to kinetic
kinetic.subscribe(scrollY)
```

## Examples

- **[All](https://codepen.io/collection/AMJybY/)**
- [Scroll Y](https://codepen.io/broadsw0rd/full/rzgamQ)
- [Scroll X](https://codepen.io/broadsw0rd/full/OjYXVG)
- [Scroll XY](https://codepen.io/broadsw0rd/full/QMREGj)

## API

## Development

Command | Description
------- | -----------
`npm run check` | Check standard code style by [snazzy](https://www.npmjs.com/package/snazzy)
`npm run build` | Wrap source code in [UMD](https://github.com/umdjs/umd) by [rollup](http://rollupjs.org/)
`npm run min` | Minify code by [UglifyJS](https://github.com/mishoo/UglifyJS)