mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
types: fix event listener typing
This commit is contained in:
parent
0a701e549c
commit
1237ee6c2c
@ -8,7 +8,7 @@ const CLASSNAME = 'van-overflow-hidden';
|
||||
export function useLockScroll(element: HTMLElement) {
|
||||
const { start, move, deltaY, direction } = useTouch();
|
||||
|
||||
function onTouchMove(event: TouchEvent) {
|
||||
const onTouchMove = ((event: TouchEvent) => {
|
||||
move(event);
|
||||
|
||||
if (direction.value !== 'vertical') {
|
||||
@ -29,9 +29,9 @@ export function useLockScroll(element: HTMLElement) {
|
||||
if (prevent) {
|
||||
preventDefault(event, true);
|
||||
}
|
||||
}
|
||||
}) as EventListener;
|
||||
|
||||
function lock() {
|
||||
const lock = () => {
|
||||
if (!count) {
|
||||
document.body.classList.add(CLASSNAME);
|
||||
}
|
||||
@ -39,7 +39,7 @@ export function useLockScroll(element: HTMLElement) {
|
||||
count++;
|
||||
on(document, 'touchstart', start);
|
||||
on(document, 'touchmove', onTouchMove);
|
||||
}
|
||||
};
|
||||
|
||||
lock();
|
||||
|
||||
|
@ -23,21 +23,21 @@ export function useTouch() {
|
||||
const offsetY = ref(0);
|
||||
const direction = ref('');
|
||||
|
||||
function reset() {
|
||||
direction.value = '';
|
||||
const reset = () => {
|
||||
deltaX.value = 0;
|
||||
deltaY.value = 0;
|
||||
offsetX.value = 0;
|
||||
offsetY.value = 0;
|
||||
}
|
||||
direction.value = '';
|
||||
};
|
||||
|
||||
function start(event: TouchEvent) {
|
||||
const start = ((event: TouchEvent) => {
|
||||
reset();
|
||||
startX.value = event.touches[0].clientX;
|
||||
startY.value = event.touches[0].clientY;
|
||||
}
|
||||
}) as EventListener;
|
||||
|
||||
function move(event: TouchEvent) {
|
||||
const move = ((event: TouchEvent) => {
|
||||
const touch = event.touches[0];
|
||||
deltaX.value = touch.clientX - startX.value;
|
||||
deltaY.value = touch.clientY - startY.value;
|
||||
@ -47,7 +47,7 @@ export function useTouch() {
|
||||
if (!direction.value) {
|
||||
direction.value = getDirection(offsetX.value, offsetY.value);
|
||||
}
|
||||
}
|
||||
}) as EventListener;
|
||||
|
||||
return {
|
||||
move,
|
||||
|
@ -1,7 +1,5 @@
|
||||
import { inBrowser } from '..';
|
||||
|
||||
type EventHandler = (event: Event) => void;
|
||||
|
||||
// eslint-disable-next-line import/no-mutable-exports
|
||||
export let supportsPassive = false;
|
||||
|
||||
@ -23,7 +21,7 @@ if (inBrowser) {
|
||||
export function on(
|
||||
target: EventTarget,
|
||||
event: string,
|
||||
handler: EventHandler,
|
||||
handler: EventListenerOrEventListenerObject,
|
||||
passive = false
|
||||
) {
|
||||
if (inBrowser) {
|
||||
@ -35,7 +33,11 @@ export function on(
|
||||
}
|
||||
}
|
||||
|
||||
export function off(target: EventTarget, event: string, handler: EventHandler) {
|
||||
export function off(
|
||||
target: EventTarget,
|
||||
event: string,
|
||||
handler: EventListenerOrEventListenerObject
|
||||
) {
|
||||
if (inBrowser) {
|
||||
target.removeEventListener(event, handler);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user