diff options
author | Thedro Neely <thedroneely@gmail.com> | 2019-04-09 05:36:46 -0400 |
---|---|---|
committer | Thedro Neely <thedroneely@gmail.com> | 2019-04-09 05:36:46 -0400 |
commit | 57bc45c39006ff52b085781df453edaba165fbec (patch) | |
tree | 404a0fb4dcc759c399807d2505df188ab2fe05d0 /public/js/app.js | |
parent | e1702c4100ae51172be82b2f068ceab30109214c (diff) | |
download | thedroneely.com-57bc45c39006ff52b085781df453edaba165fbec.tar.gz thedroneely.com-57bc45c39006ff52b085781df453edaba165fbec.tar.bz2 thedroneely.com-57bc45c39006ff52b085781df453edaba165fbec.zip |
public/js/app: Add velocity
Diffstat (limited to 'public/js/app.js')
-rw-r--r-- | public/js/app.js | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/public/js/app.js b/public/js/app.js index c04fcb2..1721a38 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -80,16 +80,21 @@ var previousPosition = window.pageYOffset; var navbar = document.getElementById("navbar"); var navbarHeight = navbar.offsetHeight; +if (previousPosition > navbarHeight) { + addClass(navbar, 'navbar__headroom'); +} + window.onscroll = function() { remClass(activeMenu, 'is-active'); remClass(activeBurger, 'is-active'); remClass(activeBurgerCompact, 'is-active'); var currentPosition = window.pageYOffset; + var velocity = previousPosition - currentPosition; - if (previousPosition > currentPosition) { + if (velocity > 55 || currentPosition < navbarHeight) { remClass(navbar, 'navbar__headroom'); - } else if (currentPosition > navbarHeight) { + } else if (velocity < 0) { addClass(navbar, 'navbar__headroom'); } |