选择/拖动文本时停止页面滚动

发布于 2024-11-27 11:47:39 字数 109 浏览 0 评论 0原文

我有一个页面,我不希望用户能够滚动。为了防止这种情况,我只是将主体设置为隐藏溢出样式。直到用户尝试选择一些文本然后拖动到底部为止,这已经足够了。然后窗口会随着用户的拖动而滚动。我怎样才能防止这种情况发生?

I have a page where I do not want the user to be able to scroll. In order to prevent it, I just set the body to have a hidden overflow style. This is sufficient up until the point where a user tries to select some text and then drags to the bottom. The window then scrolls with the users dragging. How can I prevent this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暮年 2024-12-04 11:47:39

使用位置:固定;。如果您希望整个正文不可滚动:

body
{
  position: fixed;
}

编辑:收到用户 Sam 的评论后,我决定返回并再次测试此方法。现在我重新考虑它,Sam 担心它会扰乱样式,我得出的结论是,以下将是一个更好的解决方案:

html
{
  position: fixed;
  width: 100%;
  height: 100%;
}

防止某些网站(包括 stackoverflow)最终左对齐。它还使用可用的最高节点,这应该首先完成。

use position: fixed;. If you want the whole body to be non-scrollable:

body
{
  position: fixed;
}

EDIT: after receiving the comment from user Sam, I've decided to go back and test this method once again. Now that I reconsider it and Sam's concern that it would mess with styles, I've come to the conclusion that the following would be a better solution:

html
{
  position: fixed;
  width: 100%;
  height: 100%;
}

The prevents some sites (stackoverflow included) from ending up left aligned. It also uses the highest node available, which should have been done in the first place.

尬尬 2024-12-04 11:47:39

我尝试了约瑟夫的回答,但它可能会弄乱网站上的很多风格。

另一种方法是将网站的溢出设置为隐藏,这也远非理想,但它并没有搞乱我的任何样式,希望这对某人有帮助。

body {
  overflow-y: hidden;     
}

I tried Josephs answer but it can mess up a lot of the style on the website.

Another way would be to set the overflow of the website to hidden, this is also far from ideal but it didn't mess up any styling for me, hopefully this is helpful to someone.

body {
  overflow-y: hidden;     
}
顾忌 2024-12-04 11:47:39

这可能会有帮助

html
{
    overflow: hidden;

}

It can be helpfull

html
{
    overflow: hidden;

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文