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

micro-touch

v0.2.0

Published

Super basic mobile gesture support tool.

Downloads

18

Readme

micro-touch

NPM version

Super basic mobile gesture support tool.
NPM page: https://www.npmjs.com/package/micro-touch

Installation

npm install micro-touch --save

User Guide

import {TouchGesture} from "micro-touch";

tou = new TouchGesture(DOM);
let t2d = new Transform2D(tou.el)
// tou.on("tap", tap);
// tou.on("longTap", longTap);
// tou.on("doubleTap", doubleTap);
// tou.on("pressMove", function (e) {
//     let {moveDistance, startDistance} = e;
//     console.log(moveDistance, startDistance);
// });
tou.on("pinch", function (e) {
    let {pointAngle,startAngle,pointSpace,startSpace,scale,rotate} = e;
    t2d.setRotate(rotate);
})
结合mmicro-transform2d实现拖拽阻力

let pullN = 0.2;

let tg = new TouchGesture(divDom.current);
let t2d = new Transform2D(divDom.current);
t2d.setTranslate(50, 0);

tg.on("tapDown", function () {
    divDom.current.style.removeProperty("transition");
    t2d.setTranslate(50, 0);
});

tg.on("pressMove", function (e) {
    let {moveDistance: {x, y, d}} = e;
    let [nowX, nowY] = t2d.getTranslate();

    if (nowY > 50) {
        y *= pullN;
    }

    t2d.setTranslate(50, nowY + y);
});

tg.on("tapUp", function () {
    divDom.current.style.transition = "500ms";
    t2d.setTranslate(50, 0);
});

Note

传入一个DOM对象,对其进行方法监听

  • new TouchGesture(DOM)

  • on(gesture,callback) : 注册事件监听回调函数

    • 'tap' : 元素被单击
    • 'doubleTap' : 元素被双击
    • 'longTap' : 长按元素一秒
    • 'pressMove' : 移动元素
    • 'pinch' : 双指缩放或者旋转时触发
    • "tapDown" | "tapMove" | "tapUp" : 等同于touchstart,touchmove,touchend,但是拓展了事件属性
  • off() : 取消注册的回调函数

  • destroy() : 销毁注册实例

  • interval(lastTime: number, duration: number = 500) : Promise对象判定给定时间是否和当前时间满足间隔

  • getMove(p1: point, p2: point) : 获取两个点之间的距离对象

  • getAngle(move: move) : 解析move对象,返回角度值(弧度制)

  • getMiddlePoint(p1: point, p2: point) : 获取两个点之间的中点坐标

  • radian2angle() : 弧度转角度

  • angle2radian() : 角度转弧度

Resources

You can read micro-touch Documentation online for more information.

License

micro-touch uses the MIT license, see LICENSE file for the details.