Created
April 30, 2023 11:21
-
-
Save Arifursdev/4f38c9813561e6d638ae5caca642d1c4 to your computer and use it in GitHub Desktop.
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
function getVisiblePercentage(element) { | |
const rect = element.getBoundingClientRect(); | |
const windowHeight = window.innerHeight || document.documentElement.clientHeight; | |
const visibleHeight = Math.min(rect.bottom, windowHeight) - Math.max(rect.top, 0); | |
const percentage = visibleHeight / rect.height * 100; | |
return percentage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment