Skip to content

Instantly share code, notes, and snippets.

@indreklasn
Created September 14, 2019 09:10
Show Gist options
  • Save indreklasn/688c4415b50a464e040726ea216f0b7c to your computer and use it in GitHub Desktop.
Save indreklasn/688c4415b50a464e040726ea216f0b7c to your computer and use it in GitHub Desktop.
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