Skip to content

Commit b9cdbe8

Browse files
committed
feat(range): 优化代码
1 parent 8540ec8 commit b9cdbe8

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/utils/use-touch.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,11 @@ export function useTouch() {
4242
}
4343

4444
const getX = (touch: React.Touch) => {
45-
if (typeof touch.screenX !== 'undefined') return touch.screenX
46-
if (typeof touch.pageX !== 'undefined') return touch.pageX
47-
if (typeof touch.clientX !== 'undefined') return touch.clientX
48-
return 0
45+
return touch.screenX ?? touch.pageX ?? touch.clientX ?? 0
4946
}
5047

5148
const getY = (touch: React.Touch) => {
52-
if (typeof touch.screenY !== 'undefined') return touch.screenY
53-
if (typeof touch.pageY !== 'undefined') return touch.pageY
54-
if (typeof touch.clientY !== 'undefined') return touch.clientY
55-
return 0
49+
return touch.screenY ?? touch.pageY ?? touch.clientY ?? 0
5650
}
5751

5852
const start = (event: React.TouchEvent<HTMLElement>) => {

0 commit comments

Comments
 (0)