javascript - Popper not sticking to ref element on scroll - Stack Overflow

Demo: Click on any "click me to set ref". The popper correctly positions itself. Now start sc

Demo:

Click on any "click me to set ref". The popper correctly positions itself. Now start scrolling, and you'll see the popper doesn't stick to the ref.

If you move .popper to be a direct child of .scroll-body, it works.

<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?

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

Click on any "click me to set ref". The popper correctly positions itself. Now start scrolling, and you'll see the popper doesn't stick to the ref.

If you move .popper to be a direct child of .scroll-body, it works.

<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?

Share Improve this question asked Mar 22, 2020 at 3:21 Eric GuanEric Guan 16k10 gold badges52 silver badges62 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

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. The reason is the scrollParents detection is done when the instance is created (or updated).

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

You can change the reference dynamically if you call .setOptions({}) after setting it though, but I would remend the above instead.

If you put overflow-y: scroll; on #app, it will work the way you want. Overflow-y needs to be set on the parent for it to affect the child.

I have encounter this issue, in my case, I forget to set container overflow: auto.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745360834a4624349.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信