简体   繁体   English

滚动页面时更改元素的高度将元素移动到视口之外

[英]Changing height of element moves element outside of viewport when page is scrolled

We got a list of cards that show a small part of a textbox.我们得到了一张卡片列表,其中显示了文本框的一小部分。 That textbox is limited in height via CSS.该文本框的高度通过 CSS 受到限制。 When a user clicks on "Details" the textboxes height is changed via javascript to the real height of the content.当用户单击“详细信息”时,文本框的高度通过 javascript 更改为内容的实际高度。 The problem is, that when the viewport / window is scrolled and the cards height increases, it pushes itself out of the viewport.问题是,当视口 / window 滚动并且卡片高度增加时,它会将自身推出视口。 When the window is not scrolled at all, it works.当 window 根本不滚动时,它可以工作。

Please see the following video: https://monosnap.com/file/HauaJrJlkx2MBLGt3QOa5ulJMxFTnv请观看以下视频: https://monosnap.com/file/HauaJrJlkx2MBLGt3QOa5ulJMxFTnv

0:00 -> 0:08 is the desired opening / closing behavior that I want 0:00 -> 0:08 是我想要的打开/关闭行为

0:09 -> 0:16 is the behavior I do not want, as the top text is moved out of the viewport. 0:09 -> 0:16 是我不想要的行为,因为顶部文本已移出视口。

Is there a way to keep the viewport, preferably without JS?有没有办法保留视口,最好不用JS?

Edit: This happens only in Chrome (84.0.41), in Firefox and Safari it works as expected.编辑:这仅在 Chrome (84.0.41)、Firefox 和 Safari 中发生,它按预期工作。

I can send you a link to the staging environment if necessary, please contact me via info@felixhagspiel.de如有必要,我可以向您发送登台环境的链接,请通过 info@felixhagspiel.de 与我联系

Looks it's done more logical that you want to be.看起来它比你想要的更合乎逻辑。 As control placed in a bottom element (bad UI) better keep this control in viewport (strange that chest Crome thinks so).由于控件放置在底部元素(糟糕的 UI)中,因此最好将此控件保留在视口中(奇怪的是 Crome 的胸部这么认为)。

So just display:flex build all this magic:)所以只需display:flex构建所有这些魔法:)

Please look examples https://drive.google.com/file/d/1faTDwJBQEv-V96O8-HC-8R2_hXkGzsQJ/view?usp=sharing请查看示例https://drive.google.com/file/d/1faTDwJBQEv-V96O8-HC-8R2_hXkGzsQJ/view?usp=sharing

UPDATE: also please remove更新:也请删除

tabindex="0" 

And use button instead div to get the same logic with the keyboard navigation.并使用button而不是div来获得与键盘导航相同的逻辑。

On Video last Chrome Google Chrome is up to date Version 84.0.4147.89 (Official Build) (64-bit) On Video last Chrome Google Chrome 是最新版本 84.0.4147.89 (Official Build) (64-bit)

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

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