Added URL fragment support for tabs

This commit is contained in:
2026-06-12 05:44:43 +01:00
parent 99131cea6f
commit a607318eff

View File

@ -44,6 +44,12 @@ function switchTab(tabID, playAnimation=true) {
tabID = tabID.id.split('button-')[1];
}
if (currentTab == tabID) { return; }
console.log(`Switching from ${currentTab} to ${tabID}...`);
currentTab = tabID;
location.hash = `#${tabID}`;
let tabTransitionTime = Number(getComputedStyle(document.body).getPropertyValue('--tab-transition-time').slice(0, -2));
let tabs = document.getElementsByTagName('main')[0].children;
let tab = document.getElementById(`tab-${tabID}`);
@ -94,6 +100,10 @@ function switchTab(tabID, playAnimation=true) {
button.classList.add('buttonHighlight');
}
window.addEventListener('hashchange', (e) => {
switchTab(location.hash.slice(1));
});
window.addEventListener('load', (e) => {
switchTab('home', false);