1

I m using the scrollIntoView function to go from one section to another on my webpage.

I would using some function to adjust the scroll. Currently the scroll make the section appear at top of page but my fixed top menu then hide a part of the section.

To make the section fully displayed on the page after the scrollIntoView I have tried to use the function window.scrollBy to make the scrollY backs on top of 150px, hence revealing the previously hidden part of the element.

But it fails.

Here my snippet:

scrollToElement = (target)=> {
        target.scrollIntoView({behavior: 'smooth'})
        // window.scrollBy(0,-150)
} 

How adjust my scrollIntoView please?

Any hint would be great, thanks

Webwoman
  • 10,196
  • 12
  • 43
  • 87
  • Perhaps because `scrollBy()` runs immediately after `scrollIntoView()` is invoked with `smooth` behavior and does not wait for it to finish scrolling – haim770 May 15 '19 at 15:30
  • maybe it is possible to get the number of pixel that scrollIntoView would use and push it directly in a scrollTo function using the smooth behavior option? – Webwoman May 15 '19 at 15:31
  • If that's indeed the problem, see https://stackoverflow.com/q/52292603/1625737 – haim770 May 15 '19 at 15:33
  • yes but it is a callback, I will dive to find if it exist a way to adjust directly the pixel that srollIntoView will use like `target.scrollIntoView({behavior: 'smooth', pixelAdjustment: y})` – Webwoman May 15 '19 at 15:53

0 Answers0