npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

swipe_event_jquery

v1.0.3

Published

Adds jQuery events when a swipe has occurred.

Downloads

7

Readme

jQuery Event Swipe

A simple jQuery event swipe library. When a swipe happens an event will be triggered.

Install with npm install swipe_event_jquery

I needed a simple method to figure out if a swipe had happened or not and none of the libraries currently available gave me a an easy to manage drop in method. So I made my own.

This library is focussed on pure node project integration that will be compiled with something into a single JS file that's served to the browser, and will not run as a stand alone, in a non node enviroment, unless you modify the source a bit. The events will attach themselves to whichever jQuery instance is returned by require('jquery');

Read the documentation and play with the demo on https://tschallacka.github.io/npm_jquery_event_swipe/

There are four events.

$(element).on("swipe.up", (e) => {});
$(element).on("swipe.down", (e) => {});
$(element).on("swipe.left", (e) => {});
$(element).on("swipe.down", (e) => {});
$(element).on("swipe.all", (e) => {}); // Triggers on all swipe directions

the event object

The event will be triggered on the element that was swiped. The directional event is triggered first, then the "all" event will run. preventDefault has no effect on these events.

The event object will have the following relevant properties:

event.direction
Can be "up", "down", "left" and "down"

event.distance
The distance covered in the recorded swipe in pixels. This is the distance along the measured axis, not accounting for extra distance traveled along the perpendicular axis.

event.duration
How long it took for the swipe to complete.
To calculate the speed you can divide distance / duration.

event.deviation The deviation perpendicular to the swipe direction. Can be negative or positive.

Gotcha

When looking for an up or down swipe, please note that that the document will continue to scroll/flinged to position. There are several tricks you can apply, but they vary by use case. One trick you might consider using is setting the overflow-y property on the document when the touchstart happens within a wrapping element

let $swipefield = $('.swipefield');
    $body = $('body');
	
$swipefield.on('touchstart', (e) => {
	$body.css({
		'overflow-y': 'hidden'
	});
});
$swipefield.on('touchend', (e) => {
	$body.css({
		'overflow-y':''
	});
});

Managing the settings.

There are three settings that can be managed for the swiper.

threshold
How many pixels need to be travelled at a minimum to count as a swipe and not a tap.
default 50

restraint
Maximum numbers of pixels that can be travelled at an a perpendicular direction that it can still be counted as a swipe and not a scroll.
So if you are swiping left you allow the swipe this many pixels to deviate to the top and bottom. default 200

For example, these are swipes with the orange path marking the movement of the swipe. The black line is the starting point of the swipe, the gray lines showing how many pixels up and down it moves. The orange line shows the path of the swipe.

Valid swipes at restraint 200:
deviation to the top, valid
deviation to the bottom, valid
deviation relatively straight, valid

Invalid swipes because they deviate too much:

deviation to the top, invalid
deviation to the bottom, invalid

allowedTime
Maximum time in milliseconds for a swipe to complete. Otherwise it may be a slow scroll.
default 300

You can set these settings by using the function returned by npm's require.

let swipeSettingsManager = require('jquery_event_swipe');
swipeSettingsManager({
	threshold: 50,
	restraint: 200,
	allowedTime: 300
});

You don't need to set them all at once, only the ones you need changed. Do keep in mind that the changes are global.

let swipeSettingsManager = require('jquery_event_swipe');
swipeSettingsManager({
	allowedTime: 100
});