Created
March 25, 2023 16:42
-
-
Save crazy4groovy/c4fd2318c5ca46478214ee84fd7a8d7d to your computer and use it in GitHub Desktop.
Detect when an element resizes with ResizeObserver (JavaScript)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myObserver = new ResizeObserver(entries => { | |
entries.forEach(entry => { | |
console.log('width', entry.contentRect.width); | |
console.log('height', entry.contentRect.height); | |
}); | |
}); | |
const someEl = document.querySelector('.some-element'); | |
myObserver.observe(someEl); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment