Skip to content

Commit

Permalink
only run sticky header script if enabled, avoid running when undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
JugglerX committed Oct 30, 2024
1 parent 2c35c2c commit 4abfc96
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
36 changes: 19 additions & 17 deletions assets/js/scripts.js
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");
}
});
}
2 changes: 1 addition & 1 deletion exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ title = "Hugo Serif Theme"
favicon = "favicon-32x32.svg"

[params.homepage]
sticky_header = false
sticky_header = true
show_contact_box = true # show / hide the contaxt box on the homepage
show_services_button = false # show / hide the "view all services" button

Expand Down

0 comments on commit 4abfc96

Please sign in to comment.