Skip to content

Improvement in JS #2

Open
Open
@Imran-imtiaz48

Description

@Imran-imtiaz48

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions