mirror of
https://codeberg.org/angestoepselt/homepage.git
synced 2025-05-24 14:46:16 +00:00
Scroll the title element in the tab widget into view after switching
This commit is contained in:
parent
536f3932c4
commit
97bef91387
2 changed files with 22 additions and 0 deletions
20
assets/main.js
Normal file
20
assets/main.js
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
for (const tabLinkElement of document.querySelectorAll(
|
||||||
|
'h2 + .tabs-widget > a[href]'
|
||||||
|
)) {
|
||||||
|
const titleElement = tabLinkElement.parentElement.previousElementSibling;
|
||||||
|
tabLinkElement.addEventListener('click', (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const hash = tabLinkElement.getAttribute('href');
|
||||||
|
if (history.replaceState) {
|
||||||
|
// This is a weird hack to make sure that the :target selectors actually
|
||||||
|
// get updated:
|
||||||
|
// https://github.com/whatwg/html/issues/639#issuecomment-252716663
|
||||||
|
history.replaceState(null, '', hash);
|
||||||
|
history.pushState(null, '', hash);
|
||||||
|
history.back();
|
||||||
|
titleElement.scrollIntoView(true);
|
||||||
|
} else {
|
||||||
|
location.hash = hash;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
@ -100,5 +100,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
<script src="/assets/main.js" lang="text/javascript"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue