negomi / react-burger-menu

:hamburger: An off-canvas sidebar component with a collection of effects and styles using CSS transitions and SVG path animations
http://negomi.github.io/react-burger-menu/
MIT License
5.05k stars 586 forks source link

Scroll page to top doesn't work #338

Closed minecraft00z closed 5 years ago

minecraft00z commented 5 years ago

Hello. I've successfully implemented react burger menu on my site and it works. Now I want to add "Scrooll to top" button on my pages. I implemented this functionality earlier by scrolling window to the top:

 window.scrollTo({
      top: 100,
      left: 100,
      behavior: 'smooth'
   });

But with the menu on the page it doesn't work. I think this is because we set 'overflow: auto' on the #page-wrap. When I disable 'overflow: auto' on the #page-wrap, scrolling starts to work, but when I open the menu my page suddenly scrolls to the top. Is it possible to somehow add scrolling to top functionality with 'overflow: auto' still being applied to the #page-wrap?

negomi commented 5 years ago

Hey @minecraft00z, yes, you would just need to scroll on the #page-wrap element instead of window (as that is the element that scrolls):

const pageWrap = document.getElementById('page-wrap');

pageWrap.scrollTo({
    top: 100,
    left: 100,
    behavior: 'smooth'
});