G
G
Greg Popov2016-07-17 13:59:20
Angular
Greg Popov, 2016-07-17 13:59:20

How to make a smooth, not jerky scrollTop in Angular v.1?

Actually the whole question in the topic. Looked around a bunch of resources, found nothing. That delay, then twitches, everything is not of high quality.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Lebedev, 2016-07-17
@Gregpopov

It's just not clear what Angular has to do with it.

// Плавная прокрутка в начало
document.querySelector('.goTop').addEventListener('click', function() {
  return up();
});

function up() {
  // чем меньше значение, тем выше скорость перемещения
  window.scrollBy(0, -30);
  // если значение меньше нуля, то скролл на верху
  if (window.pageYOffset > 0) {
    return requestAnimationFrame(up);
  }
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question