react-tiny-virtual-list icon indicating copy to clipboard operation
react-tiny-virtual-list copied to clipboard

Animate scroll to index

Open acollazomayer opened this issue 5 years ago • 8 comments

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

acollazomayer avatar Sep 05 '18 19:09 acollazomayer

nvm i already modified the library to do so

acollazomayer avatar Sep 05 '18 20:09 acollazomayer

Maybe submit a PR?

Kadajett avatar Oct 11 '18 16:10 Kadajett

@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.

acollazomayer avatar Oct 16 '18 16:10 acollazomayer

Any updates on this?

gjunkie avatar Apr 19 '19 21:04 gjunkie

Any updates?

riccio82 avatar Aug 12 '19 09:08 riccio82

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);
};

ramneekhanda avatar Jan 13 '20 16:01 ramneekhanda

Thanks @ramneekhanda ! Nice trick!

riccio82 avatar Jan 20 '20 14:01 riccio82

Or just

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

for vertical scroll

dmitriypereverza avatar Apr 08 '22 10:04 dmitriypereverza