@gdjiami/jslib
Version:
Jiami FrontEnd helpers and Services
86 lines (85 loc) • 2.33 kB
TypeScript
/**
* DOM 相关的函数
*/
/**
* 隐藏元素
* 运用于应用的开场动画或者动画切换
*
* @param element CSS 选择器
* @param className 隐藏效果类名
* @param timeout 延迟隐藏时间
*
* @example
*
* ```js
* hide('.my-el', 'hide')
* ```
*/
export declare function hide(element: string, className: string, timeout?: number): void;
/**
* 通过 script 异步加载资源,用于动态导入外部链接资源
* 在需要使用到某个外部资源时,通过动态导入,实现按需加载
*
* @param src 注入的脚本字符串
*
* @example
*
* ```js
* importScript(`http://xxx.js`)
* ```
*/
export declare function importScript(src: string): Promise<undefined>;
/**
* 动态生成 css 类名
* 通过传入kv对象,在判断value值,动态计算节点类名
* 运用于状态切换时,类名的变化
*
* @param opt key-value 对象,通过判断 value 是否添加 key
* @param other 静态类名
*
* @example
*
* ```js
* cls({ active: true }, 'tab') // => 'active tab'
* cls({ active: false }, 'tab') // => ' tab'
* ```
*/
export declare function cls(opt: {
[name: string]: any;
}, ...other: string[]): string;
/**
* 在指定时间内避免重复执行操作,避免用户多次点击,触发执行操作
*
* @param fn 执行的操作
* @param duration 规定时间
*
* @example
*
* ```js
* const openIndex = preventReEnter(() => openPage('index'), 1000)
* <button onClick={openIndex}>打开首页</button>
* ```
*/
export declare function preventReEnter<T extends (...args: any[]) => void>(fn: T, duration?: number): T;
/**
* 获取限制了最大的宽度或高度后的图片的缩放大小
* const max = Math.max(w, h, maxSize)
* 当图片的宽度 === max 时,需要计算出等比情况下的图片高度;
* 当图片的高度 === max 时,需要计算出等比情况下的图片宽度;
* 否则返回原图片宽高。
*
* @param w 图片宽度
* @param h 图片高度
* @param maxSize 图片缩放的最大尺寸
*
* @example
*
* ```js
* getImgWHByMax(100, 100, 200)
* // => { w: 100, h: 100}
* ```
*/
export declare function getImgWHByMax(w: number, h: number, maxSize: number): {
w: number;
h: number;
};