选择/拖动文本时停止页面滚动 [英] stop the page scrolling when selecting/dragging text

查看:184
本文介绍了选择/拖动文本时停止页面滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,我不想让用户滚动。为了防止它,我只是设置了身体有一个隐藏的溢出风格。这是足够的,直到用户试图选择一些文本然后拖动到底部的点。然后窗口随用户拖动滚动。如何防止这种情况?

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?

推荐答案

使用 position:fixed; 。如果你想让整个机体不可滚动:

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

body
{
  position: fixed;
}

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

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%;
}

防止某些网站(包括stackoverflow)它还使用可用的最高节点,这应该是在第一位。

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.

这篇关于选择/拖动文本时停止页面滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆