Teal TealUI

悬停事件web/hover

模拟 CSS :active 伪类。

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

hover(box, e => {
    box.className += " doc-box-blue";
}, e => {
    box.className = "doc-box";
})
</script>

API

函数 描述
hover(elem, ...)(elem:HTMLElement, pointerEnter?:function, pointerLeave?:function, delay?:number):void

设置指针悬停时的回调函数。

参数 类型 描述 默认值
elem* HTMLElement
pointerEnter (e: MouseEvent) => void
pointerLeave (e: MouseEvent) => void
delay number 30

返回值

类型:void

示例

hover(elem, () => console.log("进"), () => console.log("出"))

设置指针悬停时的回调函数。