简体   繁体   English

波普尔不坚持滚动参考元素

[英]Popper not sticking to ref element on scroll

Demo: https://codesandbox.io/s/agitated-euler-rep54演示: https : //codesandbox.io/s/agitated-euler-rep54

Click on any "click me to set ref".单击任何“单击我设置参考”。 The popper correctly positions itself. popper 正确定位自己。 Now start scrolling, and you'll see the popper doesn't stick to the ref.现在开始滚动,你会看到 popper 没有粘在 ref 上。

If you move .popper to be a direct child of .scroll-body , it works.如果您将.popper移动为.scroll-body的直接子.scroll-body ,它会起作用。

<div id="app">
    <div class="scroll-body">
      <div v-for="n in 40">
          <span @click="setRef" class="ref">
            click me to set ref
          </span>
      </div>
    </div>
    <div ref="popper" class="popper">popper</div>
</div>

What popper option do I need to set to make it work?我需要设置什么 popper 选项才能使其工作?

You should avoid changing the reference after the instance has been created like state.elements.reference = newReference and instead create a fresh popper instance entirely.您应该避免在创建实例后更改引用,如state.elements.reference = newReference ,而是完全创建一个新的 popper 实例。 The reason is the scrollParents detection is done when the instance is created (or updated).原因是scrollParents检测是在创建(或更新)实例时完成的。

https://codesandbox.io/s/nifty-night-5vjfm https://codesandbox.io/s/nifty-night-5vjfm

You can change the reference dynamically if you call .setOptions({}) after setting it though, but I would recommend the above instead.如果在设置后调用.setOptions({}) ,则可以动态更改引用,但我建议改为使用上述方法。

If you put overflow-y: scroll;如果你把溢出-y:滚动; on #app, it will work the way you want.在#app 上,它将以您想要的方式工作。 Overflow-y needs to be set on the parent for it to affect the child.需要在父级上设置溢出-y 才能影响子级。

我遇到过这个问题,就我而言,我忘记设置 container overflow: auto

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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