简体   繁体   English

引导模态力滚动到顶部

[英]Bootstrap modal forces scroll to top

I'm currently trying to implement a feed of posts, where clicking on a post would open a modal. 我目前正在尝试实现帖子的供稿,在其中单击帖子将打开模式。 I'm using angular as a frontend framework and decided to use the bootstrap modal, since it works well with angular. 我将angular用作前端框架,并决定使用bootstrap模态,因为它可以很好地与angular一起使用。 Problem is, that the modal forces the body to scroll to top when showing. 问题在于,模态会迫使人体在显示时滚动到顶部。 This is ofcourse not ideal when scrolling through a feed. 当然,这在滚动Feed时并不理想。

The css line below is the culprit. 下面的css行是元凶。 Why this causes the problem to occur, i do not know, but i kind of need the scrollbar to be always showing. 我不知道为什么这会导致问题发生,但我有点需要滚动条始终显示。 Loaading of dynamic content would otherwise make my layout jump around. 动态内容的浮动可能会使我的布局跳来跳去。

html {
    overflow-y: scroll;
}

Removing this line is fine right now, but i need to find a fix soon, as the layout would jump horizontally when loading new content, if the scrollbar is not always visible and then suddenly appearing. 删除此行现在很好,但是我需要尽快找到一个解决方法,因为如果滚动条不总是可见并且突然出现,则在加载新内容时布局会水平跳动。 Does anyone have any clue as to why this causes the problem, and how i can possibly fix it? 有谁有任何线索,为什么这会导致问题,以及我怎么可能解决它?

Sounds like the modal is the problem. 听起来模态是问题所在。 Make sure your modal or its outer-most container has position: fixed , as it sounds like it is disrupting the flow of the <body> element. 确保您的模式容器或其最外部的容器具有position: fixed ,因为这听起来像正在干扰<body>元素的流程。

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

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