Git Product home page Git Product logo

rosin's Introduction

rosin

A tiny single-finger tap and swipe library. Works with touch and/or mouse events. 700 bytes gzipped.

Install

npm i rosin --save

Usage

import rosin from "rosin";

const swiper = rosin(document.body);

Emitted values are relative to the DOM node you instantiated on.

swiper.on("tap", ({ x, y }, e) => {});
swiper.on("mouseup", ({ x, y }, e) => {});
swiper.on("mousedown", ({ x, y }, e) => {});

/** Fired once on each swipe */
swiper.on("left", ({ x, y }, e) => {});
swiper.on("right", ({ x, y }, e) => {});
swiper.on("up", ({ x, y }, e) => {});
swiper.on("down", ({ x, y }, e) => {});

Drag events emit a different payload. It looks like this:

{
  ix, // initial X coordinate
  iy, // initial Y coordinate
  dx, // delta (change) in X coordinate
  dy, // delta (change) in Y coordinate
  x,  // current X coordinate
  y,  // current Y coordinate
}
/** Fired on every animation frame */
swiper.on("drag", (coords, e) => {});
swiper.on("dragLeft", (coords, e) => {});
swiper.on("dragRight", (coords, e) => {});
swiper.on("dragUp", (coords, e) => {});
swiper.on("dragDown", (coords, e) => {});

Each emitter also returns a function to destroy itself:

const tapListener = swiper.on("tap", () => {});

tapListener(); // destroy listener

To destroy the entire instance:

swiper.destroy();

License

MIT License © Eric Bailey

rosin's People

Contributors

estrattonbailey avatar

Stargazers

Roman avatar Andrejs Agejevs avatar Aleksejs Skurjats avatar Sadegh Barati avatar Ben Cooper avatar Simon Goetz avatar  avatar Mario Loncarek avatar John Roberts avatar fro avatar Stephen Tetreault avatar Sylvain avatar Fabian Mersch avatar Nikolas Evers avatar Vishal Sancheti avatar Johnie Hjelm avatar Tobias Bleckert avatar Denis Denisov avatar  avatar Eugene Lee avatar Ruud Luijten avatar Terkel avatar Mike Wagz avatar Adam Seckel avatar Vilav B. avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.