leilukin-site/shrines/starwarskotor/js/header.js

30 lines
1.0 KiB
JavaScript
Raw Normal View History

2023-07-26 07:40:22 +00:00
/* Header component content */
2023-06-27 14:57:47 +00:00
document.querySelector("header").innerHTML = `
<img src="/shrines/starwarskotor/img/swkotor-header.jpg" alt="">
`;
2023-07-26 07:40:22 +00:00
/* Navigation component content */
2023-06-27 14:57:47 +00:00
document.querySelector("nav").innerHTML = `
<ul class="nav__menu">
2023-07-26 07:40:22 +00:00
<li><a href="/shrines/starwarskotor/">Home</a></li>
<li><a href="/shrines/starwarskotor/articles/">Articles</a></li>
<li><a href="/shrines/starwarskotor/guides/">Guides</a></li>
<li><a href="/shrines/starwarskotor/resources/">Resources</a></li>
<li><a href="/home.html">Main Site</a></li>
2023-06-27 14:57:47 +00:00
</ul>
2023-07-26 07:40:22 +00:00
`;
/* MAKE THE NAVBAR STICKY */
const header = document.querySelector("header");
const navbar = document.querySelector("nav");
window.addEventListener("scroll", e => {
const scrollPos = window.scrollY || document.documentElement.scrollTop;
const stickyLine = header.scrollHeight - navbar.scrollHeight;
if (scrollPos > stickyLine) {
navbar.classList.add("sticky-nav");
} else {
navbar.classList.remove("sticky-nav");
}
});