23 lines
563 B
JavaScript
23 lines
563 B
JavaScript
(function () {
|
|
var activeLink = document.querySelector('.nav a.active');
|
|
if (!activeLink) {
|
|
return;
|
|
}
|
|
|
|
var links = Array.prototype.slice.call(document.querySelectorAll('.nav a'));
|
|
|
|
function setActiveFromHash() {
|
|
var hash = window.location.hash || '#start';
|
|
links.forEach(function (link) {
|
|
if (link.getAttribute('href') === hash) {
|
|
link.classList.add('active');
|
|
} else {
|
|
link.classList.remove('active');
|
|
}
|
|
});
|
|
}
|
|
|
|
window.addEventListener('hashchange', setActiveFromHash);
|
|
setActiveFromHash();
|
|
})();
|