-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
only run sticky header script if enabled, avoid running when undefined
- Loading branch information
Showing
2 changed files
with
20 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
var body = document.querySelector('body') | ||
var menuTrigger = document.querySelector('#toggle-main-menu-mobile'); | ||
var menuContainer = document.querySelector('#main-menu-mobile'); | ||
var body = document.querySelector("body"); | ||
var menuTrigger = document.querySelector("#toggle-main-menu-mobile"); | ||
var menuContainer = document.querySelector("#main-menu-mobile"); | ||
|
||
menuTrigger.onclick = function() { | ||
menuContainer.classList.toggle('open'); | ||
menuTrigger.classList.toggle('is-active') | ||
body.classList.toggle('lock-scroll') | ||
} | ||
menuTrigger.onclick = function () { | ||
menuContainer.classList.toggle("open"); | ||
menuTrigger.classList.toggle("is-active"); | ||
body.classList.toggle("lock-scroll"); | ||
}; | ||
|
||
window.onscroll = function() {makesticky()}; | ||
var header = document.getElementById("stickyHeader"); | ||
var sticky = header.offsetTop; | ||
function makesticky() { | ||
if (window.pageYOffset > sticky) { | ||
header.classList.add("sticky"); | ||
} else { | ||
header.classList.remove("sticky"); | ||
} | ||
} | ||
|
||
if (header) { | ||
var offset = header.offsetTop; | ||
document.addEventListener("scroll", function () { | ||
if (window.scrollY > offset) { | ||
header.classList.add("sticky"); | ||
} else { | ||
header.classList.remove("sticky"); | ||
} | ||
}); | ||
} |
This file contains 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