Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions apify-docs-theme/static/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,43 @@
// load();
// }
// }, 500);

let lastKnownScrollHash = '';
let ticking = false;

function doSomething() {
const hash = window.location.hash.substring(1);

if (hash !== lastKnownScrollHash) {
console.log(hash, `li[data-item-id="${hash}"]`);

Check warning on line 43 in apify-docs-theme/static/js/custom.js

View workflow job for this annotation

GitHub Actions / Lint app code

Unexpected console statement
const $li = document.querySelector(`li[data-item-id="${hash}"]`);

if (!$li) {
return;
}

// not visible, click on the parent <li> first
if (!$li.offsetParent) {
$li.parentElement?.parentElement?.click();
}

$li.scrollIntoView({
// smooth would be nice, but it's not working in some case
// behavior: 'smooth',
block: 'nearest',
inline: 'center',
});
lastKnownScrollHash = hash;
}
}

document.addEventListener('scroll', () => {
if (!ticking) {
window.requestAnimationFrame(() => {
doSomething();
ticking = false;
});

ticking = true;
}
});