Created
September 14, 2019 09:10
-
-
Save indreklasn/688c4415b50a464e040726ea216f0b7c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "./styles.css"; | |
// first import. | |
import Headroom from "headroom.js"; | |
// grab the header element. | |
const Header = document.querySelector("header"); | |
// construct an instance of Headroom, passing the header elemen. | |
const headroom = new Headroom(Header, { | |
offset: 0, | |
tolerance: { | |
up: 0, | |
down: 0 | |
}, | |
classes: { | |
initial: "header--fixed", | |
pinned: "slideDown", | |
unpinned: "slideUp", | |
top: "top", | |
notTop: "not-top" | |
} | |
}); | |
// initialise | |
headroom.init(); | |
// When the page is at the top, remove the slideDown class. | |
window.addEventListener("scroll", () => { | |
if (window.pageYOffset === 0) { | |
Header.classList.remove("slideDown"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment