[英]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
我有一个
position:fixed
div与e.scrollIntoView
overflow-y:scroll
因为e.scrollIntoView
方法工作正常, window.scroll
和scrollto
方法未应用于此固定div,但尝试滚动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. 是否可以使
window.scroll
或window.scrollTo
方法在固定的div容器中工作。
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 在此处查看演示: https : //codepen.io/anon/pen/mXJMrx
Is that what you want? 那是你要的吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.