Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: only prevent scroll if browser will do it #32

Open
cyan-2048 opened this issue May 27, 2024 · 0 comments
Open

Suggestion: only prevent scroll if browser will do it #32

cyan-2048 opened this issue May 27, 2024 · 0 comments

Comments

@cyan-2048
Copy link

scroll happens when element isn't in viewport, so let's check if it's in viewport or not

function isElementInViewport (el) {
    var rect = el.getBoundingClientRect();

    return (
        rect.top >= 0 &&
        rect.left >= 0 &&
        rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
        rect.right <= (window.innerWidth || document.documentElement.clientWidth)
    );
}

this should work for all browsers, i think this polyfill is doing too much work even if nothing has scrolled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant