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

detect end of scrolling #130

Open
vAhyThe opened this issue Feb 4, 2019 · 1 comment
Open

detect end of scrolling #130

vAhyThe opened this issue Feb 4, 2019 · 1 comment

Comments

@vAhyThe
Copy link

vAhyThe commented Feb 4, 2019

How is there some callback when i finished my scroll

i have

// console.log(element.scrollLeft)  = 0
element.scrollBy({ top: 0, left: -984, behavior: 'smooth' })
// console.log(element.scrollLeft)  = 0

it is possible add some callback ?? thx

@schwigri
Copy link

schwigri commented Oct 16, 2019

Here is what I usually do for scrolling to certain positions. You may be able to adjust it to use element.scrollBy() instead of window.scrollTo()

function scrollTo(position) {
  return new Promise(resolve => {
    const scrollListener = e => {
      if ('undefined' === typeof e) {
        return;
      }
      const target = e.currentTarget;
      if (target.scrollTop === position) {
        target.removeEventListener('scroll', scrollListener);
        resolve();
      }
    };
    window.addEventListener('scroll', scrollListener);
    window.scrollTo({
      top: position,
      behavior: 'smooth',
    });
  });
}

scrollTo(element.offsetTop).then(() => {
  // Do something
});

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

2 participants