使用JavaScript停用水平滚动 [英] Disable horizontal scroll with JavaScript

查看:113
本文介绍了使用JavaScript停用水平滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道是否有一种方法来禁用使用JavaScript的水平滚动条?

Does anyone know if there is a way to disable the horizontal scrollbar using JavaScript?

我不想使用 overflow-x:hidden;

推荐答案

如果不使用完全可行的 overflow-x CSS属性,您可以调整内容大小,

Without using the perfectly workable overflow-x CSS property, you could resize the content to not require a scroll bar, through javascript or through HTML/CSS design.

您也可以执行此操作:

window.onscroll = function () {
 window.scrollTo(0,0);
}

...这将检测任何滚动并自动返回滚动到顶部/剩下。

... which will detect any scrolling and automatically return the scroll to the top/left. It bears mentioning that doing something like this is sure to frustrate your users.

最好的办法是创建一个环境,其中不需要的UI元素根本不存在(通过CSS,通过设计)。上面提到的方法显示了不必要的UI元素(滚动条),然后导致它们不以用户期望的方式工作(滚动页面)。您与用户签订了合同 - 当用户进行熟悉的操作时,他们如何相信您的网站或应用程序的其余部分会执行预期的操作?

You're best served by creating an environment where unwanted UI elements are not present at all (through the CSS, through design). The approach mentioned above shows unnecessary UI elements (scroll bars) and then causes them to not work in a way that the user expects (scroll the page). You've "broken a contract" with the user - how can they trust that the rest of your web site or application will do expected things when the user makes a familiar action?

这篇关于使用JavaScript停用水平滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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