敲好用的utils库:seemly

敲好用的utils库:seemly家人们 上链接 https www npmjs com package seemly Installation npm install save dev seemly Usage import xxx from seemly API Animation 动画

大家好,我是讯享网,很高兴认识大家。

家人们!上链接: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.

小讯
上一篇 2025-03-21 18:19
下一篇 2025-04-05 15:24

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/37954.html