当前位置:网站首页>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>
看个轮廓就可以了哈,反正两个都不会缩放,今天就到这里!
边栏推荐
- 淺淺的談一下ThreadLocalInsecureRandom
- Millimeter wave radar human body sensor, intelligent perception of static presence, human presence detection application
- What does software testing do? What are the requirements for learning?
- Successful entry into Baidu, 35K monthly salary, 2022 Android development interview answer
- 深度學習 卷積神經網絡(CNN)基礎
- 【C语言】字符串函数及模拟实现strlen&&strcpy&&strcat&&strcmp
- 信息/数据
- [FAQ] summary of common causes and solutions of Huawei account service error 907135701
- leetcode刷题:二叉树14(左叶子之和)
- c语言oj得pe,ACM入门之OJ~
猜你喜欢

That's awesome. It's enough to read this article

How about testing outsourcing companies?

建议收藏,我的腾讯Android面试经历分享

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

C application interface development foundation - form control (5) - grouping control

图嵌入Graph embedding学习笔记

Xaas trap: all things serve (possible) is not what it really needs

leetcode刷题:二叉树17(从中序与后序遍历序列构造二叉树)

Build your own website (16)

ACM getting started Day1
随机推荐
【c语言】归并排序
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
Do you know several assertion methods commonly used by JMeter?
Debezium series: modify the source code to support UNIX_ timestamp() as DEFAULT value
Wildcard selector
使用 RepositoryProvider简化父子组件的传值
Recommended collection, my Tencent Android interview experience sharing
Win10 x64环境下基于VS2017和cmake-gui配置使用zxing以及opencv,并实现data metrix码的简单检测
leetcode刷题:二叉树13(相同的树)
使用easyexcel模板导出的两个坑(Map空数据列错乱和不支持嵌套对象)
Information / data
Relationship between floating elements and parent and brother boxes
打新债在哪里操作开户是更安全可靠的呢
leetcode刷题:二叉树11(平衡二叉树)
How to safely and quickly migrate from CentOS to openeuler
[OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*
Common operators and operator priority
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
SecureRandom那些事|真伪随机数
Fundamentals of shell programming (Part 8: branch statements -case in)