Skip to content

Instantly share code, notes, and snippets.

@greggman
Last active August 28, 2025 18:35
Show Gist options
  • Save greggman/279bf9a730b8829cf4717f74a914126a to your computer and use it in GitHub Desktop.
Save greggman/279bf9a730b8829cf4717f74a914126a to your computer and use it in GitHub Desktop.
pointerdown/move/up test
:root {
color-scheme: light dark;
}
html {
overscroll-behavior: none;
touch-action: none;
}
<p>drag mouse/finger</p>
<pre id="log"></pre>
const lines = [];
const logElem = document.querySelector('#log');
function log(msg) {
lines.push(msg);
lines.splice(0, lines.length - 20);
logElem.textContent = lines.join('\n');
}
function onMove(e) {
e.preventDefault();
log('pointermove');
log(`${e.clientX}, ${e.clientY}`);
}
function onUp(e) {
e.preventDefault();
log('pointerup');
window.removeEventListener('pointerup', onUp);
window.removeEventListener('pointermove', onMove);
}
function onDown(e) {
log('pointerdown');
onMove(e);
window.addEventListener('pointerup', onUp, { passive: false });
window.addEventListener('pointermove', onMove, { passive: false });
}
function preventScroll(e) {
e.preventDefault();
}
//window.addEventListener('touchmove', preventScroll, { passive: false });
window.addEventListener('pointerdown', onDown, { passive: false });
log('start');
{"name":"pointerdown/move/up test","settings":{},"filenames":["index.html","index.css","index.js"]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment