Teal TealUI

按住事件web/active

模拟 CSS :active 伪类。

<div id="box" class="doc-box"></div>
<script>
import active from "web/active";

var c = 0;
active(box, e => {
    box.innerHTML = c++;
})
</script>

API

函数 描述
active(elem, ...)(elem:HTMLElement, pointerDown?:function, pointerUp?:function, duration?:number):void

设置指针按住时的回调函数。

参数 类型 描述 默认值
elem* HTMLElement
pointerDown (e: MouseEvent) => void
pointerUp (e: MouseEvent) => void
duration number 50

返回值

类型:void

示例

active(elem, () => console.log("下"), () => console.log("上"))

设置指针按住时的回调函数。