|
|
@ -62,17 +62,45 @@
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
|
|
<script>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const nav = document.querySelector(".navbar");
|
|
|
|
// Function to run when the DOM is fully loaded
|
|
|
|
let lastScrollY = window.scrollY;
|
|
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
|
|
|
|
|
|
// Find all checkboxes
|
|
|
|
window.addEventListener("scroll", () => {
|
|
|
|
var checkboxes = document.querySelectorAll('input[type="checkbox"]');
|
|
|
|
if (lastScrollY < window.scrollY) {
|
|
|
|
|
|
|
|
nav.classList.add("navbar--hidden");
|
|
|
|
// Loop over each checkbox
|
|
|
|
} else {
|
|
|
|
checkboxes.forEach(function(checkbox) {
|
|
|
|
nav.classList.remove("navbar--hidden");
|
|
|
|
// Create the switch
|
|
|
|
}
|
|
|
|
var switchElement = document.createElement('label');
|
|
|
|
|
|
|
|
switchElement.className = 'switch';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create the input for the switch
|
|
|
|
|
|
|
|
var input = document.createElement('input');
|
|
|
|
|
|
|
|
input.type = 'checkbox';
|
|
|
|
|
|
|
|
input.checked = checkbox.checked;
|
|
|
|
|
|
|
|
switchElement.appendChild(input);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create the slider for the switch
|
|
|
|
|
|
|
|
var slider = document.createElement('span');
|
|
|
|
|
|
|
|
slider.className = 'slider';
|
|
|
|
|
|
|
|
switchElement.appendChild(slider);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add the switch to the page
|
|
|
|
|
|
|
|
checkbox.parentNode.insertBefore(switchElement, checkbox.nextSibling);
|
|
|
|
|
|
|
|
|
|
|
|
lastScrollY = window.scrollY;
|
|
|
|
// Hide the original checkbox
|
|
|
|
|
|
|
|
checkbox.style.display = 'none';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// When the switch is clicked, update the checkbox
|
|
|
|
|
|
|
|
input.addEventListener('change', function() {
|
|
|
|
|
|
|
|
checkbox.checked = this.checked;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// When the checkbox is updated (e.g. by JavaScript), update the switch
|
|
|
|
|
|
|
|
var observer = new MutationObserver(function() {
|
|
|
|
|
|
|
|
input.checked = checkbox.checked;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
observer.observe(checkbox, { attributes: true });
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|