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

mobile-gestures

v2.0.4

Published

A mobile terminal gesture events.

Downloads

17

Readme

Introduction

Before this time, I wrote about mobile simple gestures event code, when I thought I wrote well, but six months later, the original code I still not often used, beacuse the use way is different from the js binding of the native event, people use it uncomfortable.

But now, I did it.

Using proxy, we can bind our own custom events like binding native events, and it's not surprising that we can delete events and decide on event-triggered time.

This is the repository,named mobie-gestures.

Install

As an es6 module

You can install it by using npm:

	$ npm install mobile-gestures --save

and then(better in code top-level scope),

	import 'mobile-gestures'
	

As a es5 js file

You can install by using it:

	<script src='./path/mobile-gestures/dist/gestures.common.js'></script>
	

Usage

Now, you can use it just like using native events.for example:

Using in js script

	document.getElementById('gesture').addEventListener('doubletap', (e) =>{
	  console.log(e)
	})

Using in Vue.js

	<img @scale.stop.prevent="scaleImg($event)" />
	

and ...

Gesture Types

tap

When you put a finger on the element and then quickly released on the element, it will trigger the tap event.The event will save the touch-related information on changedTouches, targetTouches, touches,and all of them are one-dimensional array.

doubletap

When you tap on an element twice with one finger in 300ms Quickly, it will trigger the doubletap event.The event will save the touch-related information on changedTouches, targetTouches, touches,and all of them are one-dimensional array.

longtap

When you put a finger on the element and stay in 500ms,it will trigger the longtap event.The event will save the touch-related information on changedTouches, targetTouches, touches,and all of them are one-dimensional array.

move

WHen you put one finger on the element ans move on it, it will trigger the move event.The event will save the touch-related information on changedTouches, targetTouches, touches,and all of them are two-dimensional array.

swipeup

When you put a finger on the element and swipe up, it will trigger the swipeup event.The event will save the touch-related information on changedTouches, targetTouches, touches,and all of them are two-dimensional array.

Note: During one touch, the event is triggered only one time.

swiperight

When you put a finger on the element and swipe right, it will trigger the swiperight event.The event will save the touch-related information on changedTouches, targetTouches, touches,and all of them are two-dimensional array.

Note: During one touch, the event is triggered only one time.

swipedown

When you put a finger on the element and swipe down, it will trigger the swipedown event.The event will save the touch-related information on changedTouches, targetTouches, touches,and all of them are two-dimensional array.

Note: During one touch, the event is triggered only one time.

swipeleft

When you put a finger on the element and swipe left, it will trigger the swipelwft event.The event will save the touch-related information on changedTouches, targetTouches, touches,and all of them are two-dimensional array.

Note: During one touch, the event is triggered only one time.

scale

When you put two fingers on the element and scale it, it will trigger the scale event.The event will save the touch-related information on changedTouches, targetTouches, touches,and all of them are two-dimensional array.In addition,the event also save the scale proportion on the scale property.

rotate

When you put two fingers on the element and rotate it, it will trigger the rotate event.The event will save the touch-related information on changedTouches, targetTouches, touches,and all of them are two-dimensional array.In addition,the event also save the rotate angle on the rotation property.

release

When you remove the last one finger from the element,it will trigger the release event.The event will save the touch-related information on changedTouches, targetTouches, touches,and all of them are one-dimensional array.

Prevent Events

Before the version 1.0.7, I use the event.preventDefault() at the gestures type events whicth cause some serious problems that make some scrollable elements cannot be scrollable due to the touches events's default behavior is scrolling.and to make some gestures can work and to prevent the browser default behavior,I add some prevent events to do it.It is simple and you can use it friendly.

Using in js script

	document.getElementById('gesture').addEventListener('preventleft', null)

Using in Vue.js

	<img @preventleft />
	

and ...

preventall

Simplely using event.preventDefault() to prevent all touches events's default behavior.

preventup

Only when you swipeup on the element, the event.preventDefault() is valid, and other ways, it will be not valid.

preventright

Only when you swiperight on the element, the event.preventDefault() is valid, and other ways, it will be not valid.

preventdown

Only when you swipedown on the element, the event.preventDefault() is valid, and other ways, it will be not valid.

preventleft

Only when you swipeleft on the element, the event.preventDefault() is valid, and other ways, it will be not valid.

preventlongtap

When you longtap on the element, I find a HTMLElement events contextmenu that can prevent some browser's longtap default behavior, but not useful at all browsers(such as UC browser). and For IOS devise, you may need css -webkit-touch-callout: none; to fixed it. And for all devices, you may need css property user-select: none; to prevent css default behavior.And anyway, I test the preventlongtap event on chrome and weixin, it works. so I add it for some cases you may need it.

Touch-Related information

ALl the gesture events preserve touch-related information,But how to read them?

In one-dimensional array.the each element is your touches point,and save them same as your touch time.

In Two-dimensional array, the first element is the touch point that you first touch point, and the next element is the touch point that you next touch point. And the first element is not changed after you taped,but next element amy not due to them will be changed due to your fingers move.

Add demos

I add some simple demos at this version, and you can see it at the repository github address mobile-gestures.Enjoy use it!

Note

At this version, I removed the gesture slowtap due to thinking that is not nessary and you can use the tap gesture instead.

The Blog

js移动端手势事件重写