Skip to content

Instantly share code, notes, and snippets.

@lmiller1990
Created December 7, 2019 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmiller1990/b77b7322560bf6f9835fb627c03d71af to your computer and use it in GitHub Desktop.
Save lmiller1990/b77b7322560bf6f9835fb627c03d71af to your computer and use it in GitHub Desktop.
import Vue from 'vue'
import { getScrollPercentage } from './progress'
interface IData {
percent: number
scrollEvent: ((this: Window, ev: Event) => void) | null
}
export default Vue.extend({
name: 'Progress',
data(): IData {
return {
percent: 0,
scrollEvent: null,
}
},
mounted() {
const progressStartMarker = document.querySelector<HTMLElement>('#progress-marker-start')
const progressEndMarker = document.querySelector<HTMLElement>('#progress-marker-end')
if (!progressStartMarker || !progressEndMarker) {
throw Error('Progress markers not found')
}
window.addEventListener('scroll', () => {
this.percent = getScrollPercentage(progressStartMarker, progressEndMarker)
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment