Skip to content

Instantly share code, notes, and snippets.

@hkitago
Last active April 14, 2023 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkitago/537ba7e5c741b2825e6fd7bc2b3bd290 to your computer and use it in GitHub Desktop.
Save hkitago/537ba7e5c741b2825e6fd7bc2b3bd290 to your computer and use it in GitHub Desktop.
to add EventListener to swipe nodes.
const swipeNodes = document.querySelectorAll('.swipe')
let isTouched = false
const basePoint = {'x': 0, 'y': 0, }
Array.from(swipeNodes).map((x) => {
x.addEventListener('touchstart', (e) => {
e.preventDefault()
isTouched = true
basePoint['x'] = e.touches[0].clientX
basePoint['y'] = e.touches[0].clientY
})
x.addEventListener('touchmove', (e) => {
if(!isTouched) {return false}
e.preventDefault()
const distPoint = {'x': e.touches[0].clientX - basePoint['x'],'y': e.touches[0].clientY - basePoint['y'],}
/* do something */
})
x.addEventListener('touchend', (e) => {
if(!isTouched) {return false}
e.preventDefault()
isTouched = false
/* do something */
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment