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

Consider using the browser's scroll-behavior for smooth scrolling #4306

Open
philc opened this issue Sep 17, 2023 · 2 comments
Open

Consider using the browser's scroll-behavior for smooth scrolling #4306

philc opened this issue Sep 17, 2023 · 2 comments

Comments

@philc
Copy link
Owner

philc commented Sep 17, 2023

It seems like all modern browsers now support smooth scrolling as an argument to window.scrollBy. Can we rely on the browser's smooth scrolling implementation and remove the Vimium "use smooth scrolling" and "step size" options?

It seems reasonable to me that if the user has disabled smooth scrolling in the browser, then Vimium will inherit that preference and not have smooth scrolling. What do you think?

The first step is to POC this and see if the browser's implementation is equivalent to Vimium's current implementation.

Related issues:

@gdh1995
Copy link
Contributor

gdh1995 commented Sep 23, 2023

The smooth scrolling is not as convenient as I once expected: if I hold on j to scroll longer, then a sequence of element.scrollBy({ y: 60, behavior: "smooth"}) will behave very weird, mainly because browser always interrupts an old scrolling and starts a new one.

@bastianpedersen
Copy link

I'm not familiar into the intricacies of how scrolling is implemented in Vimium, so I do apologize if my suggestion is strange. Would it be possible to try to change the custom scroll code to as easy as this and see how it behaves? I would love to do it myself, but looking at the existing code I feel completely lost. The code below is taken from a forked Vimari extension and it works really well.

var scrollTarget = -1;
var scrollTargetResetTimeout = null;

function customScrollBy(x, y) {
    if (scrollTarget == -1)
        scrollTarget = window.pageYOffset + y;
    else
        scrollTarget += y;

    window.scroll({ left: x, top: scrollTarget, behavior: 'smooth' });

    clearTimeout(scrollTargetResetTimeout);
    scrollTargetResetTimeout = setTimeout(() => {
      scrollTarget = -1;
    }, 100)
}

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

No branches or pull requests

3 participants