Skip to content

Instantly share code, notes, and snippets.

@rniwa
Created October 15, 2019 02:10
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 rniwa/6dacd1c9cb8a28daff086d58830ddd88 to your computer and use it in GitHub Desktop.
Save rniwa/6dacd1c9cb8a28daff086d58830ddd88 to your computer and use it in GitHub Desktop.
resize event test
<!DOCTYPE html>
<html>
<body>
<pre id="log"></pre>
<script>
let lastSize = null;
function updateSize() {
const width = window.innerWidth;
const height = window.innerHeight;
const newSize = `${width}px by ${height}px`;
if (lastSize == newSize)
return;
lastSize = newSize;
document.getElementById('log').textContent += newSize + '\n';
setTimeout(updateSize, 5);
}
window.addEventListener('resize', () => {
lastSize = null;
document.getElementById('log').textContent += 'windowResize:';
updateSize();
});
if (window.visualViewport) {
visualViewport.addEventListener('resize', () => {
lastSize = null;
document.getElementById('log').textContent += 'visualviewportResize:';
updateSize();
});
}
setTimeout(updateSize, 5);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment