useMouse
跟踪鼠标位置。
Usage
实时编辑器
function Demo() { const mouse = useMouse(); return ( <div> <p> Client - x: {mouse.clientX}, y: {mouse.clientY} </p> <p> Page - x: {mouse.pageX}, y: {mouse.pageY} </p> <p> Screen - x: {mouse.screenX}, y: {mouse.screenY} </p> </div> ); };
结果
Loading...
API
useMouse
Returns
UseMouseCursorState
: 鼠标位置
Arguments
参数名 | 描述 | 类型 | 默认值 |
---|---|---|---|
target | dom元素 | BasicTarget | - |
UseMouseCursorState
Type
export interface UseMouseCursorState { screenX: number screenY: number clientX: number clientY: number pageX: number pageY: number elementX: number elementY: number elementH: number elementW: number elementPosX: number elementPosY: number }
BasicTarget
export type BasicTarget<T extends TargetType = Element> = (() => TargetValue<T>) | TargetValue<T> | MutableRefObject<TargetValue<T>>;
TargetValue
type TargetValue<T> = T | undefined | null;