2016-10-03 18:19:13 +00:00
|
|
|
//- 💫 MAIN JAVASCRIPT
|
2016-03-31 14:24:48 +00:00
|
|
|
|
2016-10-31 18:04:15 +00:00
|
|
|
'use strict'
|
2016-03-31 14:24:48 +00:00
|
|
|
|
2016-10-03 18:19:13 +00:00
|
|
|
{
|
2016-10-31 18:04:15 +00:00
|
|
|
const nav = document.querySelector('.js-nav')
|
|
|
|
const fixedClass = 'is-fixed'
|
|
|
|
let vh, scrollY = 0, scrollUp = false
|
2016-03-31 14:24:48 +00:00
|
|
|
|
2016-10-31 18:04:15 +00:00
|
|
|
const updateVh = () => Math.max(document.documentElement.clientHeight, window.innerHeight || 0)
|
2016-03-31 14:24:48 +00:00
|
|
|
|
2016-10-03 18:19:13 +00:00
|
|
|
const updateNav = () => {
|
2016-10-31 18:04:15 +00:00
|
|
|
const vh = updateVh()
|
|
|
|
const newScrollY = (window.pageYOffset || document.scrollTop) - (document.clientTop || 0)
|
2017-02-08 14:08:33 +00:00
|
|
|
if (newScrollY != scrollY) scrollUp = newScrollY <= scrollY
|
2016-10-31 18:04:15 +00:00
|
|
|
scrollY = newScrollY
|
2016-03-31 14:24:48 +00:00
|
|
|
|
2016-10-31 18:04:15 +00:00
|
|
|
if(scrollUp && !(isNaN(scrollY) || scrollY <= vh)) nav.classList.add(fixedClass)
|
2017-02-08 20:33:22 +00:00
|
|
|
else if (!scrollUp || (isNaN(scrollY) || scrollY <= vh/2)) nav.classList.remove(fixedClass)
|
2016-03-31 14:24:48 +00:00
|
|
|
}
|
|
|
|
|
2016-10-31 18:04:15 +00:00
|
|
|
window.addEventListener('scroll', () => requestAnimationFrame(updateNav))
|
2016-10-03 18:19:13 +00:00
|
|
|
}
|