Skip to content

Commit

Permalink
prevent topBar flicker when loading a scrolled page
Browse files Browse the repository at this point in the history
my bad
  • Loading branch information
ornicar committed Mar 19, 2024
1 parent 801f6a5 commit 13c254e
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions ui/site/src/topBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,10 @@ export default function () {

{
// stick top bar
let lastY = 0;
let lastY = window.scrollY;
if (lastY > 0) top.classList.add('scrolled');

const onScroll = () => {
window.addEventListener('scroll', () => {
const y = window.scrollY;
top.classList.toggle('scrolled', y > 0);
if (y > lastY + 10) top.classList.add('hide');
Expand All @@ -190,9 +191,6 @@ export default function () {
else return;

lastY = Math.max(0, y);
};

window.addEventListener('scroll', onScroll);
requestAnimationFrame(() => window.scrollY > 0 && top.classList.add('scrolled'));
});
}
}

0 comments on commit 13c254e

Please sign in to comment.