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