Created
December 19, 2018 07:48
-
-
Save jhealey5/e6ac63c94bb09cd283418396f1171350 to your computer and use it in GitHub Desktop.
Gets scrolled percentage of page relative to element
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
| getPercentage(){ | |
| let wh = window.innerHeight, | |
| scroll = window.pageYOffset, | |
| height = this.$el.offsetHeight, | |
| top = this.$el.getBoundingClientRect().top + scroll; | |
| let distance = (scroll) - top; | |
| let percentage = distance / ((height - wh - 180) / 100); | |
| return Math.max(Math.min(Math.round(percentage), 100), 0); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment