Skip to content

Instantly share code, notes, and snippets.

View MZOG's full-sized avatar

Marcin Zogrodnik MZOG

View GitHub Profile
@MZOG
MZOG / js-add-class-after-scroll.js
Created September 25, 2019 08:16
JS add class after scroll
let scrollpos = window.scrollY
const header = document.querySelector("nav")
const header_height = header.offsetHeight
const add_class = () => header.classList.add("fade-in")
const remove_class = () => header.classList.remove("fade-in")
window.addEventListener('scroll', function() {
scrollpos = window.scrollY;
$('a[href*="#"]')
// Remove links that don't actually link to anything
.not('[href="#"]')
.not('[href="#0"]')
.click(function (event) {
// On-page links
if (location.hostname == this.hostname) {
// Figure out element to scroll to
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');