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

Jquery Lag when Scrolling #10

Closed
Tracked by #3
sortedcord opened this issue Nov 16, 2021 · 3 comments · Fixed by #11
Closed
Tracked by #3

Jquery Lag when Scrolling #10

sortedcord opened this issue Nov 16, 2021 · 3 comments · Fixed by #11
Assignees
Labels
Area: Script Improvements or additions to scripting bug Something isn't working Priority: 1

Comments

@sortedcord
Copy link
Member

I have a header minimise when I scroll down, however I have a lag for it returning to full size upon returning back to the top of the page. Seems to be worse when I scroll further.

A Simplified code snipped-

$(document).ready(function () {
    $("header").animate({
        height: "140px"
    }, 200);
    $("header>h2").show(200);
});

$(window).scroll(function () {
    if ($(document).scrollTop() > 0) {
        $("header").animate({
            height: "70px"
        }, 200);
        $("header>h2").hide(200);
    } else {
        $("header").animate({
            height: "140px"
        }, 200);
        $("header>h2").show(200);
    }
});

It does not appear to get the same problem if I set the animation time to 0 which is why I'm assuming that it's the animations that are the issue.

Is there some kind of inherent lag associated with them, like it having to wait until one's finished to do the next? If so (or any other reason for it) is it possible to overcome it and still have the animations?

@sortedcord sortedcord added bug Something isn't working Area: Script Improvements or additions to scripting Priority: 1 labels Nov 16, 2021
@sortedcord sortedcord self-assigned this Nov 16, 2021
sortedcord pushed a commit that referenced this issue Nov 16, 2021
@sortedcord
Copy link
Member Author

The issue is that each time you scroll, an animation is triggered with a 200ms transition. These queue up and process one by one which is why you see the lag. You can stop any existing animations on each scroll:

$("header").stop();

@sortedcord sortedcord pinned this issue Nov 16, 2021
@sortedcord
Copy link
Member Author

In case, somebody still faces this issue, the only thing that can be done is to wait for a minute or so and then reload the page. Apparently this seems to be an issue for browsers when they first load the site but then after a while it fixes itself automatically

@sortedcord sortedcord added the wontfix This will not be worked on label Nov 16, 2021
@sortedcord sortedcord removed the wontfix This will not be worked on label Nov 16, 2021
@sortedcord
Copy link
Member Author

Nvm I fixed it

@sortedcord sortedcord mentioned this issue Nov 16, 2021
7 tasks
@sortedcord sortedcord unpinned this issue Nov 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Script Improvements or additions to scripting bug Something isn't working Priority: 1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant