Skip to content

Instantly share code, notes, and snippets.

@jhealey5
Created December 19, 2018 07:48
Show Gist options
  • Select an option

  • Save jhealey5/e6ac63c94bb09cd283418396f1171350 to your computer and use it in GitHub Desktop.

Select an option

Save jhealey5/e6ac63c94bb09cd283418396f1171350 to your computer and use it in GitHub Desktop.
Gets scrolled percentage of page relative to element
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