GithubHelp home page GithubHelp logo

thaipham / jquery-singleclick Goto Github PK

View Code? Open in Web Editor NEW

This project forked from omriyariv/jquery-singleclick

0.0 1.0 0.0 10 KB

jQuery plugin for adding a custom 'singleclick' event to differentiate a single-click from a double-click

License: MIT License

JavaScript 100.00%

jquery-singleclick's Introduction

jquery-singleclick

jQuery plugin for adding a custom 'singleclick' event to differentiate a single-click from a double-click. The custom 'singleclick' event is fired after a standard click event with a small delay to make sure that the original first click wasn't a part of a double-click.

Installation

Clone this repository or install via Bower or npm.

bower install jquery-singleclick
npm install jquery-singleclick

Usage

Start by including the plugin in your app.

Using a simple HTML script tag:
<script src="jquery-2.1.4.js"></script>
<script src="jquery-singleclick.js"></script>
Or using an AMD loader:
require('jquery-singleclick', function($) {
    // When using AMD the plugin will look for the 'jquery' dependancy.
});

After including the plugin, you'll be able to register handlers for the custom 'singleclick' event as you would register any other jQuery handler:

$('#someElement').on('singleclick', function(e) {
    console.log('I was clicked once only');
});

$('#someElement').on('click', function(e) {
    console.log('I was clicked');
});

$('#someElement').on('dblclick', function(e) {
    console.log('I was double-clicked');
});

In the above example, double-clicking the element will trigger 2 'click' events followed by a 'dblclick' event, but no 'singleclick' event. However, if the element is only clicked once, a 'click' event will be immediately fired, followed by a delayed 'singleclick' fired after we are certain that this is not a double-click.

Configuration

The default delay time to account for a double-click is 250 miliseconds. This can be configured:

// Two clicks 750ms apart will be considered as a double-click and the 'singleclick' event will not be fired.
$.event.special.singleclick.timeout = 750;

jquery-singleclick's People

Contributors

omriyariv avatar

Watchers

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