forked from MapComplete/MapComplete
UX: add helper for gps selector
This commit is contained in:
parent
c215051ec5
commit
886b25c0b4
4 changed files with 108 additions and 6 deletions
36
src/Utils/dragDetection.ts
Normal file
36
src/Utils/dragDetection.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
export function dragDetection(htmlElement: HTMLElement, callback: () => {}) {
|
||||
|
||||
let isDown = false
|
||||
let threshold = 5
|
||||
let start = null
|
||||
|
||||
htmlElement.addEventListener("pointerdown", (e) => {
|
||||
isDown = true
|
||||
start = { x: e.clientX, y: e.clientY }
|
||||
})
|
||||
|
||||
htmlElement.addEventListener("pointermove", (e) => {
|
||||
if (!isDown || !start) return
|
||||
const dx = e.clientX - start.x
|
||||
const dy = e.clientY - start.y
|
||||
if (Math.hypot(dx, dy) > threshold) {
|
||||
callback()
|
||||
isDown = false
|
||||
}
|
||||
})
|
||||
|
||||
htmlElement.addEventListener("pointerup", () => {
|
||||
isDown = false
|
||||
start = null
|
||||
})
|
||||
|
||||
htmlElement.addEventListener("pointerleave", () => {
|
||||
isDown = false
|
||||
start = null
|
||||
})
|
||||
|
||||
return {
|
||||
destroy: () => {
|
||||
},
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue