useMousePressed
跟踪鼠标按下状态
Usage
实时编辑器
function Demo() { const [mouse, type] = useMousePressed(); return ( <div> <p>Pressed: {JSON.stringify(mouse)}</p> <p>SourceType: {JSON.stringify(type)}</p> </div> ); };
结果
Loading...
API
useMousePressed
Returns
readonly [boolean, UseMousePressedSourceType]
: 包含以下元素的元组:
- 鼠标是否按下。
- 按下的事件来源。
Arguments
参数名 | 描述 | 类型 | 默认值 |
---|---|---|---|
target | dom对象 | BasicTarget<Element> | - |
options | 可选参数 | UseMousePressedOptions | undefined | - |
UseMousePressedOptions
参数名 | 描述 | 类型 | 默认值 |
---|---|---|---|
touch | 监听 touchstart 事件 | boolean | true |
drag | 监听 dragStart 事件 | boolean | true |
initialValue | 初始值 | boolean | (() => boolean) | false |
UseMousePressedSourceType
Type
export type UseMousePressedSourceType = 'mouse' | 'touch' | null
BasicTarget
export type BasicTarget<T extends TargetType = Element> = (() => TargetValue<T>) | TargetValue<T> | MutableRefObject<TargetValue<T>>;
TargetValue
type TargetValue<T> = T | undefined | null;
TargetType
type TargetType = HTMLElement | Element | Window | Document | EventTarget;