简体   繁体   中英

Window.scroll / scrollTo method to work in position:fixed div rather then document.body

I have a position:fixed div with overflow-y:scroll since e.scrollIntoView method works fine, window.scroll and scrollto methods not being applied to this fixed div but tries to scroll document.body

Is there any workaround with this situation ? is it possible to make window.scroll or window.scrollTo method to work in fixed div container.

Looking forward to hear thank you.

What about something like this:

function scrollto(elemSelector) {
  var $wrapper = document.querySelector('.fixed-wrapper'),
      $el = document.querySelector(elemSelector);
  $wrapper.scrollTop = $el.offsetTop;
} 

See the demo here: https://codepen.io/anon/pen/mXJMrx

Is that what you want?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM