Created
October 8, 2019 09:24
-
-
Save timrijkse/ca0f0f7c9ca4c7fdc5129004f85cf37c to your computer and use it in GitHub Desktop.
Get scroll percentage of element. When the top of the element hits the top of the screen percentage will be 0. When the bottom of the element hits the bottom of the screen percentage will be 100.
This file contains 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 { top, height } = this.$el.getBoundingClientRect() | |
const { pageYOffset, innerHeight } = window | |
const min = top + pageYOffset | |
const max = min + height - innerHeight | |
const percentage = ((pageYOffset - min) * 100) / (max - min) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment