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

Animate scroll to index #64

Open
acollazomayer opened this issue Sep 5, 2018 · 8 comments
Open

Animate scroll to index #64

acollazomayer opened this issue Sep 5, 2018 · 8 comments

Comments

@acollazomayer
Copy link

Hi i want to make the scroll smoother when I do scroll to index. How can i achive this

@acollazomayer
Copy link
Author

nvm i already modified the library to do so

@Kadajett
Copy link

Maybe submit a PR?

@acollazomayer
Copy link
Author

@Kadajett of course, if you need so I will make a PR, i just overide the default scrollTo method. I will add a new prop to enable smooth scroll.

@gjunkie
Copy link

gjunkie commented Apr 19, 2019

Any updates on this?

@riccio82
Copy link

Any updates?

@ramneekhanda
Copy link

ramneekhanda commented Jan 13, 2020

Use the following

VirtualList.prototype.scrollTo = function (value) {
  console.log(value)
  function scrollTo(element, direction, to, duration) {
    if (duration <= 0) return;
    const difference = to - element[direction];
    const perTick = difference / duration * 10;
    setTimeout(function () {
      element[direction] = element[direction] + perTick;
      if (element[direction] === to) return;
      scrollTo(element, direction, to, duration - 10);
    }, 10);
  }
  const scrollDirection = this.props.scrollDirection === void 0 ? 'vertical' : this.props.scrollDirection;
  if (scrollDirection === 'vertical') {
    scrollTo(this.rootNode, 'scrollTop', value, 200);
  } else scrollTo(this.rootNode, 'scrollLeft', value, 200);
};

@riccio82
Copy link

Thanks @ramneekhanda ! Nice trick!

@dmitriypereverza
Copy link

Or just

VirtualList.prototype.scrollTo = function (value) {
  this.rootNode.scrollTo({ top: value, behavior: 'smooth' });
};

for vertical scroll

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

6 participants