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-transform2d

v0.2.0

Published

A tool for quickly setting CSS Transform.

Downloads

1

Readme

micro-transform2d

NPM version

A tool for quickly setting CSS Transform
NPM page: https://www.npmjs.com/package/micro-transform2d

Installation

npm install micro-transform2d --save

User Guide

import {Transform2D} from "micro-transform2d";
let t2d = new Transform2D(tou.el);
t2d.setRotate(rotate).setTranslate(5, 5);
注意变换是有顺序区分的,如果你要求变换按照一定顺序请初始化时这样操作
import {Transform2D} from "micro-transform2d";
let t2d = new Transform2D(tou.el);
Translate会在rotate之前执行
t2d.setTranslate().setRotate();
设置相对值
import {Transform2D} from "micro-transform2d";
let t2d = new Transform2D(tou.el);
t2d.setTranslate(x, y, true);

注意setScale的开启相对值设置时是基于当前大小进行伸缩
如当前是1,传入1.5,伸缩值为1.5,
如当前是2,传入0.5,伸缩值为1,
除此之外setScale的relative参数不是接收布尔值,而是接收number或者函数

当设置relative为number时,基于这个值进行收缩,
当设置relative为函数时时,接收一个数组为当前元素的收缩值和传入的sca值,返回sca值为想要设置的收缩值
通过函数可以更加灵活控制sca值
t2d.setScale(scale, function (val) {
    let sca = relativeSca * val[1];
    return sca < 0.6 ? 0.6 : sca;
});

除了setScale之外,其余方法relative参数均为布尔值,相对于元素当前偏移值增加传入值
结合micro-touch实现拖拽阻力

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

  • new Transform2D(el)

    • el: DOM对象
  • getMatrix() : 获取Matrix属性,返回是一个大小为6的数组,代表变换矩阵

  • setMatrix([1,0,0,1,0,0]) : 设置Matrix属性

  • getTranslate() : 获取偏移translate

  • setTranslate(x,y) : 设置偏移translate

  • getScale() : 获取缩放比例

  • setScale(sca) : 设置缩放比例,原比例是1

  • getRotate() : 获取旋转角度

  • setRotate(angle) : 设置旋转角度

  • getSkew() : 获取斜切属性

  • setSkew(xAngle,yAngle) : 设置斜切属性

  • radian2angle() : 弧度转角度

  • angle2radian() : 角度转弧度

  • transform() : 获取transform属性

  • setTransform(result: RegExpMatchArray | null, val: string) :

  • reset() : 清除变换顺序用于重新初始变换应用顺序

  • origin() : 获取变换原点

  • setOrigin() : 设置变换原点

Resources

You can read transform2d Documentation online for more information.

License

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