mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
fix: mobile cursor
This commit is contained in:
1 parent
31b628049a
commit
9368d058f2
3 files changed
+16
-3
No files matched your search
+10
-2
@@ -25,25 +25,30 @@ export function AssaultCursor({ maxDistance, maxFakeDistance }: Props) {
|
||||
|
||||
useEffect(() => {
|
||||
let localX = x;
|
||||
let lastX = 0;
|
||||
|
||||
function handlePointerDown(event: PointerEvent) {
|
||||
event.preventDefault();
|
||||
|
||||
lastX = event.clientX;
|
||||
|
||||
window.addEventListener('pointermove', handlePointerMove);
|
||||
window.addEventListener('pointerup', handlePointerUp);
|
||||
}
|
||||
|
||||
function handlePointerMove(event: PointerEvent) {
|
||||
event.preventDefault();
|
||||
|
||||
|
||||
const parent = cursor.current?.parentElement;
|
||||
|
||||
if (!parent) return;
|
||||
|
||||
const width = parent.clientWidth;
|
||||
const movementX = event.clientX - lastX;
|
||||
lastX = event.clientX;
|
||||
|
||||
setX((state) => {
|
||||
localX = clamp(state + event.movementX / width, 0, 1);
|
||||
localX = clamp(state + movementX / width, 0, 1);
|
||||
return localX;
|
||||
});
|
||||
}
|
||||
@@ -62,6 +67,8 @@ export function AssaultCursor({ maxDistance, maxFakeDistance }: Props) {
|
||||
|
||||
return () => {
|
||||
cursor.current?.removeEventListener('pointerdown', handlePointerDown);
|
||||
window.removeEventListener('pointermove', handlePointerMove);
|
||||
window.removeEventListener('pointerup', handlePointerUp);
|
||||
};
|
||||
}, []);
|
||||
|
||||
@@ -75,6 +82,7 @@ export function AssaultCursor({ maxDistance, maxFakeDistance }: Props) {
|
||||
width="2pt"
|
||||
id="assault-cursor"
|
||||
style={{
|
||||
touchAction: 'none',
|
||||
transform: 'translateX(-50%)',
|
||||
backgroundColor: Var('accent-11'),
|
||||
}}
|
||||
|
||||
Reference in new issue
Block a user