2025-02-27 10:23:21 +00:00

38 lines
887 B
JavaScript

jQuery(function ($) {
// Getting links from a page and turning them into a scroll-spy bespoke menu
// FIXME when page loads with #... in url, the scroll spy gets messed up.
let links;
links = document.querySelectorAll("#one, #two, #three")
let url = window.location.href;
let innerContent = "";
links.forEach(link => {
let fullUrl = url + "#" + link.id;
innerContent += "<li><a href=\"" + fullUrl + " \" class=''>" + link.attributes.name.value + "</a></li>"
});
console.log(innerContent)
let menu;
menu = document.getElementById("menu-test-scroll-spy");
menu.innerHTML = innerContent
// Activate Scrollspy
$('.entry-content').scrollspy({
target: '#nav_menu-4'
});
// Refresh Scrollspy
$('[data-spy="scroll"]').each(function () {
$(this).scrollspy("refresh");
});
});