简体   繁体   English

Window.scroll / scrollTo方法在position:fixed div而不是document.body中工作

[英]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.scrollscrollto方法未应用于此固定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.scrollwindow.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.

相关问题 window.scroll(0,0)/window.scrollTo(0, 0) 不适用于 Chrome 中的移动设备 - window.scroll(0,0)/window.scrollTo(0, 0) are not working on mobile in Chrome JavaScript window.scroll 与 window.scrollTo? - JavaScript window.scroll vs. window.scrollTo? 当在文档末尾添加视口高度和窗口scrollTop位置时,jQuery $(document.body).height()不相同 - Jquery $(document.body).height() is not same when viewport height is added with the window scrollTop position, at the end of document 调用jquery .on(document.body)而不是特定元素是否有缺点 - Is there a downside to calling jquery .on(document.body) rather than the specific element 为什么$(window [&#39;iframeName&#39;]。document.body).html()在我更改.attr(&#39;src&#39;)时不起作用 - why $(window['iframeName'].document.body).html() doesn't work when i change .attr('src') 如何使用 window.scroll 与水平滚动来获取元素 position - How to use window.scroll with horizontal scroll to get element position 决定滚动哪个,document.documentElement或document.body - Deciding which to scroll, document.documentElement or document.body 位置固定,但滚动<body> - Position fixed, but scroll on <body> 现在修复了“ document.body为空”的问题,我得到了“ .setStyle不是函数” - “document.body is null” is fixed now I get “.setStyle is not a function” document.Body ComponentQuery - document.Body ComponentQuery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM