敲好用的utils库:seemly

家人们!上链接:https://www.npmjs.com/package/seemly

Installation

npm install --save-dev seemly

Usage

import { xxx } from 'seemly'

API

Animation 动画

beforeNextFrame(callback: Function): void

在下一帧之前调用xx回调函数。

beforeNextFrameOnce(callback: Function): void

在下一帧之前调用xx回调函数(仅一次)。

Color

在以下函数中,RGBA[number, number, number, number]RGB[number, number, number]

rgba (color: string): RGBA

获取字符串颜色的 rgba 值。

color 只能是 #000, #0000, #000000, #00000000, rgb(0, 0, 0), rgba(0, 0, 0, 0) 这样的格式。

composite (background: string | RGB | RGBA, overlay: string | RGB | RGBA): string

♥敲好用!!!获取两种颜色的合成颜色的rgba格式字符串。

举例: composite('#FFF', 'rgba(0, 0, 0, .5)') === 'rgba(127, 127, 127, 1)', composite('rgba(255, 255, 255, .5)', 'rgba(0, 0, 0, .5)') === 'rgba(85, 85, 85, 0.75)'.

CSS

depx (value: string | number): number

去除字符串中的 px

举例: depx('1px') === 1, depx('1') === 1, depx(1) === 1.

pxfy (value: string | number): string

给字符串或数字添加 px

举例:pxfy(1) === '1px', pxfy('1') === '1px', 'pxfy('1px') === '1px').

parseResponsiveProp (responsiveProp: string): Record<string, string>

将 css 实用程序类转换为 js 对象。

举例:parseResponsiveProp('6 m:12 l:24') is { '': 6, m: '12', l: '24' }

parseResponsivePropValue (responsiveProp: string, activeKey: string): string | undefined

按键获取对应的值。

举例: parseResponsiveProp('6 m:12 l:24', 'l') is '24'. parseResponsiveProp('6 m:12 l:24'), parseResponsiveProp('6 m:12 l:24', 'x') are '6'.

DOM

getScrollParent (node: Node | null): HTMLElement | Document | null

获取当前节点的可滚动父节点。

unwrapElement (target: HTMLElement | string | () => HTMLElement): HTMLElement | null

从元素 getter 函数或元素选择器中解开 HTMLElement。

如果 target 已经是 HTMLElement,将返回相同的值。

Misc

createId (length: number = 8): string

获取长度为 length 的唯一随机 id。

Q.E.D.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yorksh1re

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值