Skip to content

Instantly share code, notes, and snippets.

@Kurzdor
Created May 30, 2019 19:07
Show Gist options
  • Save Kurzdor/59203d378fa82f7874719b3606bd2437 to your computer and use it in GitHub Desktop.
Save Kurzdor/59203d378fa82f7874719b3606bd2437 to your computer and use it in GitHub Desktop.
useElYOverflow
const useElYOverflow = (ref, offset) => {
useEffect(() => {
const checkOverflow = () => {
const isOverflowing =
ref.current.offsetHeight + offset * 2 > window.innerHeight
if (isOverflowing) {
ref.current.classList.add('overflowing')
return
}
ref.current.classList.remove('overflowing')
}
const handleResize = () => {
checkOverflow()
}
checkOverflow()
window.addEventListener('resize', handleResize)
return () => {
window.removeEventListener('resize', handleResize)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment