当前位置:网站首页>js实现禁止网页缩放(Ctrl+鼠标、+、-缩放有效亲测)
js实现禁止网页缩放(Ctrl+鼠标、+、-缩放有效亲测)
2022-07-05 19:56:00 【德宏大魔王】
背景:现在是凌晨1:35我还在帮客户修改网页,要求不高但来钱快,学生党不容易啊,客户提到了很多网页的优化,其中这一条
让我头疼了许久,大家就不用踩坑了,看下面的就可以了
禁止滑轮:
window.addEventListener('mousewheel', function(event){
if (event.ctrlKey === true || event.metaKey) {
event.preventDefault();
}
},{
passive: false});
//firefox
window.addEventListener('DOMMouseScroll', function(event){
if (event.ctrlKey === true || event.metaKey) {
event.preventDefault();
}
},{
passive: false});
禁止+、- :
window.onload = function() {
document.addEventListener('keydown', function (event) {
if ((event.ctrlKey === true || event.metaKey === true) && (event.which === 61 || event.which === 107 || event.which === 173 || event.which === 109 || event.which === 187 || event.which === 189))
{
event.preventDefault();
}
}, false);
}
完整代码:
<script>
//luwenjie hualun
window.addEventListener('mousewheel', function(event){
if (event.ctrlKey === true || event.metaKey) {
event.preventDefault();
}
},{
passive: false});
//firefox
window.addEventListener('DOMMouseScroll', function(event){
if (event.ctrlKey === true || event.metaKey) {
event.preventDefault();
}
},{
passive: false});
//+_
window.onload = function() {
document.addEventListener('keydown', function (event) {
if ((event.ctrlKey === true || event.metaKey === true) && (event.which === 61 || event.which === 107 || event.which === 173 || event.which === 109 || event.which === 187 || event.which === 189))
{
event.preventDefault();
}
}, false);
}
</script>
看个轮廓就可以了哈,反正两个都不会缩放,今天就到这里!
边栏推荐
- IBM大面积辞退40岁+的员工,掌握这十个搜索技巧让你的工作效率至上提高十倍
- leetcode刷题:二叉树17(从中序与后序遍历序列构造二叉树)
- 深度學習 卷積神經網絡(CNN)基礎
- Android interview classic, 2022 Android interview written examination summary
- Jvmrandom cannot set seeds | problem tracing | source code tracing
- ffplay文档[通俗易懂]
- Summer Challenge harmonyos - realize message notification function
- Database logic processing function
- 40000 word Wenshuo operator new & operator delete
- 【c语言】归并排序
猜你喜欢
使用easyexcel模板导出的两个坑(Map空数据列错乱和不支持嵌套对象)
Redis cluster simulated message queue
leetcode刷题:二叉树15(找树左下角的值)
IBM大面积辞退40岁+的员工,掌握这十个搜索技巧让你的工作效率至上提高十倍
Based on vs2017 and cmake GUI configuration, zxing and opencv are used in win10 x64 environment, and simple detection of data matrix code is realized
How about testing outsourcing companies?
14. Users, groups, and permissions (14)
Recommended collection, my Tencent Android interview experience sharing
Microwave radar induction module technology, real-time intelligent detection of human existence, static micro motion and static perception
acm入门day1
随机推荐
sun.misc.BASE64Encoder报错解决方法[通俗易懂]
【c语言】归并排序
【无标题】
力扣 1200. 最小绝对差
c——顺序结构
【obs】libobs-winrt :CreateDispatcherQueueController
C#应用程序界面开发基础——窗体控制(5)——分组类控件
Inventory of the most complete low code / no code platforms in the whole network: Jiandao cloud, partner cloud, Mingdao cloud, Qingliu, xurong cloud, Jijian cloud, treelab, nailing · Yida, Tencent clo
软件测试是干什么的?学习有啥要求?
国信证券在网上开户安全吗?
gst-launch的-v参数
通配符选择器
Redis cluster simulated message queue
字节跳动Dev Better技术沙龙成功举办,携手华泰分享Web研发效能提升经验
third-party dynamic library (libcudnn.so) that Paddle depends on is not configured correctl
leetcode刷题:二叉树16(路径总和)
爬虫练习题(二)
Jvmrandom cannot set seeds | problem tracing | source code tracing
【C语言】字符串函数及模拟实现strlen&&strcpy&&strcat&&strcmp
Add data to excel small and medium-sized cases through poi