Open
Description
there are a few minor improvements and issues to consider:
-- Unnecessary use of this: In the scroll event listener, this refers to the window object. It's more clear to use document directly.
-- Performance considerations: Adding and removing a class on every scroll event can cause performance issues. Consider debouncing the scroll event to improve performance.
To Improve JS script:
`let lastKnownScrollPosition = 0;
let ticking = false;
window.addEventListener('scroll', function () {
lastKnownScrollPosition = window.scrollY;
if (!ticking) {
window.requestAnimationFrame(function () {
if (lastKnownScrollPosition >= 720) {
document.body.classList.add('sticky');
} else {
document.body.classList.remove('sticky');
}
ticking = false;
});
ticking = true;
}
});`
Metadata
Metadata
Assignees
Labels
No labels