4

I use window.scrollBy() for smooth scroll but it doesn't work for Safari. What is the best way to fix it?

function scroll(id: number) {
  for (let k = 0; k < sectionsForScroll.length; k++) {
    if (sectionsForScroll[k].dataset.navId == id) {
      const bigginer = sectionsForScroll[0].getBoundingClientRect().top;
      console.log(bigginer + 'px  how far we from the start ');

      const distanceToGo = sectionsForScroll[k].getBoundingClientRect().top;
      console.log(sectionsForScroll[k].offsetTop);

      const distanceToScroll = bigginer - distanceToGo;
      console.log(distanceToGo + ' where we have to go ');
      console.log(distanceToScroll + ' what the distanse we need to scroll ');

      window.scrollBy({left:0, top:distanceToGo, behavior:"smooth"});
    }
  }
}
adiga
  • 34,372
  • 9
  • 61
  • 83
Noa
  • 424
  • 1
  • 3
  • 16
  • Use element.scrollTop(). kindly refer https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTop – Ashish Feb 05 '19 at 08:55

0 Answers0