Giter Site home page Giter Site logo

nickhingston / react-fastclick Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jakesidsmith/react-fastclick

0.0 2.0 0.0 66 KB

Fast Touch Events for React

Home Page: https://www.npmjs.com/package/react-fastclick

License: MIT License

JavaScript 100.00%

react-fastclick's Introduction

React Fastclick CircleCI

Instantly make your desktop / hybrid apps more responsive on touch devices.

React Fastclick automatically adds fastclick touch events to elements with onClick attributes (and those that require special functionality, such as inputs) to prevent the delay that occurs on some touch devices.

Installation

Use npm to install react-fastclick

npm install react-fastclick

Usage

Initialize react-fastclick in your main javascript file before any of your components are created, and you're done.

Now any calls to onClick or elements with special functionality, such as inputs, will have fast touch events added automatically - no need to write any additional listeners.

ES6

import initReactFastclick from 'react-fastclick';
initReactFastclick();

ES5

var initReactFastclick = require('react-fastclick');
initReactFastclick();

Notes

  1. The event triggered on touch devices is a modified touchend event. This means that it may have some keys that are unusual for a click event.

In order to simulate a click as best as possible, this event is populated with the following keys / values. All positions are taken from the last know touch position.

{
  // Simulate left click
  button: 0,
  type: 'click',
  // Additional key to tell the difference between
  // a regular click and a flastclick
  fastclick: true,
  // From touch positions
  clientX,
  clientY,
  pageX,
  pageY,
  screenX,
  screenY
}
  1. On some devices the elements flicker after being touched. This can be prevented by setting the css property -webkit-tap-highlight-color to transparent. Either target html, body (to prevent the flickering on all elements) or target the specific element you don't want to flicker e.g. button.

    html, body {
      -webkit-tap-highlight-color: transparent;
    }

Support

React Fastclick 3.x.x has been tested with React 15, but should support older versions also.

react-fastclick's People

Contributors

dutzi avatar ekonstantinidis avatar jakesidsmith avatar nickhingston avatar

Watchers

 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.