禁用 ctrl +鼠标在网页上滚动
如何使用 jquery 禁用网页上的 CTRL + 鼠标滚动?
我想在我的网页上禁用放大和缩小!
How can I disable CTRL + mouse scroll on web page with jquery?
I want to disable zoom in and zoom out on my web page!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,您可以这样做:
这只适用于 Firefox、Chrome 和 Opera。它不适用于 Internet Explorer。
Yes you can do this :
This will only work for Firefox, Chrome and Opera. It will not work with Internet Explorer.
这是不可能的。
相反,您应该设计页面以支持缩放。
This is not possible.
Instead, you should design your page to support zoom.
你可以这样做,我在chrome、filefox和ie上测试过。效果很好
you can do this, i've tested on chrome、filefox and ie. it work well
更新了答案,没有 Jquery,也没有副作用。
我仅使用滚动事件就成功做到了这一点,但由于某些原因,在 Chrome 上无法阻止第一个事件缩放。无论如何,第一个 ctrl+scroll 都会缩放,直到我添加了 keydown 方法。
添加 keydown 事件使我能够防止第一个滚动事件触发缩放,但随后我产生了副作用,即所有与 ctrl 键相关的快捷方式(例如刷新等)将不再起作用。
这就是为什么我还必须添加一个变量来跟踪天气或没有正在进行的滚动事件。
最后我不得不添加一个计时器,以便 var 再次设置为 false。
结果是所有 ctrl + 滚动事件(包括第一个事件)都会阻止缩放。您可以修改它来检查
-
或=
是否被保留以防止键盘缩放,但这不是我的意图。感谢 Sumesh Dubey 的回答启发我使用 keydown 事件。
Updated answer without Jquery and without the side effects.
I was successfully doing it with the just the scroll event but for some reason on chrome there was no way to prevent the first event from zooming. The first ctrl+scroll would zoom no matter what untill I added the keydown approach.
Adding the keydown event was what allowed me to prevent the first scroll event triggering a zoom but then I had the side efffect that ALL ctrl key related shortcuts such as refresh etc would no longer work at all.
This is why I had to also add a variable to track weather or not there was a scroll event in progress.
Finally I had to add a timer so that the var was set to false again.
The result is all ctrl + scroll events including the first one would prevent zoom. You could modify this to also check if
-
or=
is held to prevent the keyboard zoom as well but that was not my intention.Thanks Sumesh Dubey for his answer inspired me to use the keydown event.