Skip to content

Instantly share code, notes, and snippets.

@benhatsor
Last active September 12, 2024 14:32
Show Gist options
  • Save benhatsor/378b917fa42d4bc03c8bf32589ffd401 to your computer and use it in GitHub Desktop.
Save benhatsor/378b917fa42d4bc03c8bf32589ffd401 to your computer and use it in GitHub Desktop.
Remove Safari text selection magnifier (iPhone)
// https://discourse.threejs.org/t/iphone-how-to-remove-text-selection-magnifier/47812/11
function createHandler(func, timeout) {
let timer = null;
let pressed = false;
return function() {
if (timer) {
clearTimeout(timer);
}
if (pressed) {
if (func) {
func.apply(this, arguments);
}
clear();
} else {
pressed = true;
setTimeout(clear, timeout || 500);
}
};
function clear() {
timeout = null;
pressed = false;
}
}
const ignore = createHandler((e) => e.preventDefault(), 500);
document.body.addEventListener('touchstart', ignore, { passive: false });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment