Skip to content

Instantly share code, notes, and snippets.

@rostyq
Last active December 3, 2021 12:39
Show Gist options
  • Save rostyq/8efa063d80932fa3452a6e9f455b3ac5 to your computer and use it in GitHub Desktop.
Save rostyq/8efa063d80932fa3452a6e9f455b3ac5 to your computer and use it in GitHub Desktop.
Browser `windowmove` event
(function() {
let screenX = window.screenX;
let screenY = window.screenY;
function update() {
const movementX = window.screenX - screenX;
const movementY = window.screenY - screenY;
if (movementX != 0 || movementY != 0) {
screenX = window.screenX;
screenY = window.screenY;
const event = new Event("windowmove");
event.movementX = movementX;
event.movementY = movementY;
event.screenX = screenX;
event.screenY = screenY;
window.dispatchEvent(event);
typeof window.onwindowmove == "function" && window.onwindowmove(event);
}
window.requestAnimationFrame(update);
}
window.requestAnimationFrame(update);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment