Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "dom"

DOM 相关的函数

Index

Functions

cls

  • cls(opt: object, ...other: string[]): string
  • 动态生成 css 类名 通过传入kv对象,在判断value值,动态计算节点类名 运用于状态切换时,类名的变化

    example
    cls({ active: true }, 'tab')  // => 'active tab'
    cls({ active: false }, 'tab')  // => ' tab'

    Parameters

    • opt: object

      key-value 对象,通过判断 value 是否添加 key

      • [name: string]: any
    • Rest ...other: string[]

      静态类名

    Returns string

getImgWHByMax

  • getImgWHByMax(w: number, h: number, maxSize: number): object
  • 获取限制了最大的宽度或高度后的图片的缩放大小 const max = Math.max(w, h, maxSize) 当图片的宽度 === max 时,需要计算出等比情况下的图片高度; 当图片的高度 === max 时,需要计算出等比情况下的图片宽度; 否则返回原图片宽高。

    example
    getImgWHByMax(100, 100, 200)
    // => { w: 100, h: 100}

    Parameters

    • w: number

      图片宽度

    • h: number

      图片高度

    • maxSize: number

      图片缩放的最大尺寸

    Returns object

hide

  • hide(element: string, className: string, timeout?: number): void
  • 隐藏元素 运用于应用的开场动画或者动画切换

    example
    hide('.my-el', 'hide')

    Parameters

    • element: string

      CSS 选择器

    • className: string

      隐藏效果类名

    • Default value timeout: number = 1000

      延迟隐藏时间

    Returns void

importScript

  • importScript(src: string): Promise<undefined>
  • 通过 script 异步加载资源,用于动态导入外部链接资源 在需要使用到某个外部资源时,通过动态导入,实现按需加载

    example
    importScript(`http://xxx.js`)

    Parameters

    • src: string

      注入的脚本字符串

    Returns Promise<undefined>

preventReEnter

  • preventReEnter<T>(fn: T, duration?: number): T
  • 在指定时间内避免重复执行操作,避免用户多次点击,触发执行操作

    example
    const openIndex = preventReEnter(() => openPage('index'), 1000)
    <button onClick={openIndex}>打开首页</button>

    Type parameters

    • T: function

    Parameters

    • fn: T

      执行的操作

    • Default value duration: number = 1000

      规定时间

    Returns T

Generated using TypeDoc