diff --git a/public/assets/css/styles.css b/public/assets/css/styles.css index 670f956..6cf694b 100644 --- a/public/assets/css/styles.css +++ b/public/assets/css/styles.css @@ -39,4 +39,19 @@ section.hero video { height: 100%; object-fit: cover; z-index: -1; +} + +.anchor-link { + text-decoration: none; + opacity: 0; + transition: opacity 0.2s; +} + +h1:hover .anchor-link, +h2:hover .anchor-link, +h3:hover .anchor-link, +h4:hover .anchor-link, +h5:hover .anchor-link, +h6:hover .anchor-link { + opacity: 1; } \ No newline at end of file diff --git a/public/assets/js/header.js b/public/assets/js/header.js deleted file mode 100644 index 2db5a8e..0000000 --- a/public/assets/js/header.js +++ /dev/null @@ -1,34 +0,0 @@ -window.addEventListener('scroll', () => -{ - // Add class to body when scrolled. - document.body.classList.toggle('is-scrolled', window.scrollY > 0); - - // Parallax effect. - /** - * @type {HTMLVideoElement} - */ - const heroVid = document.querySelector('.hero video'); - heroVid.style.top = `${window.scrollY / 3}px`; - - // Highlight menu item when scrolled to section. - let current = ''; - document.querySelectorAll('.section').forEach(section => - { - const sectionTop = section.offsetTop; - - if (window.scrollY >= sectionTop - 70) - { - current = section.getAttribute('id'); - } - }); - - document.querySelectorAll('.nav-link').forEach(link => - { - link.classList.remove('active'); - - if (link.getAttribute('href') === `#${current}`) - { - link.classList.add('active'); - } - }); -}); \ No newline at end of file diff --git a/public/assets/js/navigation.js b/public/assets/js/navigation.js new file mode 100644 index 0000000..03ee273 --- /dev/null +++ b/public/assets/js/navigation.js @@ -0,0 +1,58 @@ +/** + * @type {HTMLVideoElement} + */ +const heroVid = document.querySelector('.hero video'); + +/** + * @type {NodeListOf} + */ +const navlinks = document.querySelectorAll('a.nav-link'); + +/** + * @type {NodeListOf} + */ +const sections = document.querySelectorAll('.section'); + +// Handle scroll events. +window.addEventListener('scroll', () => +{ + // Add class to body when scrolled. + document.body.classList.toggle('is-scrolled', window.scrollY > 0); + + // Parallax effect. + heroVid.style.top = `${window.scrollY / 3}px`; + + // Highlight menu item when scrolled to section. + let current = ''; + sections.forEach(section => + { + const sectionTop = section.offsetTop; + + if (window.scrollY >= sectionTop - 70) + { + current = section.getAttribute('id'); + } + }); + + navlinks.forEach(link => + { + link.classList.remove('active'); + + if (link.getAttribute('href') === `#${current}`) + { + link.classList.add('active'); + } + }); +}); + +document.querySelectorAll('h1, h2, h3, h4, h5, h6').forEach(header => +{ + if (header.id) + { + const anchor = document.createElement('a'); + anchor.className = 'anchor-link'; + anchor.href = `#${header.id}`; + anchor.innerHTML = ' # '; + header.appendChild(anchor); + } +}); \ No newline at end of file diff --git a/public/includes/head.html b/public/includes/head.html index c551ab9..b2a9a13 100644 --- a/public/includes/head.html +++ b/public/includes/head.html @@ -9,5 +9,5 @@ - + \ No newline at end of file