当前位置:网站首页>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>
看个轮廓就可以了哈,反正两个都不会缩放,今天就到这里!
边栏推荐
- 秋招字节面试官问你还有什么问题?其实你已经踩雷了
- Reptile exercises (II)
- openh264解码数据流向分析
- How to apply smart contracts more wisely in 2022?
- Cocos2d-x项目总结中的一些遇到的问题
- okcc呼叫中心有什么作用
- Webuploader file upload drag upload progress monitoring type control upload result monitoring control
- 爬虫练习题(二)
- What are general items
- Common - Hero Minesweeper
猜你喜欢
Interviewer: what is the internal implementation of set data types in redis?
Fundamentals of deep learning convolutional neural network (CNN)
Force buckle 729 My schedule I
S7-200SMART利用V90 MODBUS通信控制库控制V90伺服的具体方法和步骤
【C语言】字符串函数及模拟实现strlen&&strcpy&&strcat&&strcmp
淺淺的談一下ThreadLocalInsecureRandom
Successful entry into Baidu, 35K monthly salary, 2022 Android development interview answer
aggregate
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (半柔性对接 AutoDock)
【硬核干货】数据分析哪家强?选Pandas还是选SQL
随机推荐
Base du réseau neuronal de convolution d'apprentissage profond (CNN)
C application interface development foundation - form control (5) - grouping control
Postman core function analysis - parameterization and test report
Do you know several assertion methods commonly used by JMeter?
SecureRandom那些事|真伪随机数
leetcode刷题:二叉树10(完全二叉树的节点个数)
Autumn byte interviewer asked you any questions? In fact, you have stepped on thunder
14. Users, groups, and permissions (14)
【obs】QString的UTF-8中文转换到blog打印 UTF-8 char*
Webuploader file upload drag upload progress monitoring type control upload result monitoring control
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
使用 RepositoryProvider简化父子组件的传值
IBM has laid off 40 + year-old employees in a large area. Mastering these ten search skills will improve your work efficiency ten times
Summer Challenge harmonyos - realize message notification function
软件测试工程师是做什么的?待遇前景怎么样?
打新债在哪里操作开户是更安全可靠的呢
Complete interview questions for interviewers and senior Android engineers in front-line Internet enterprises
acm入门day1
Gstreamer中的task
Debezium series: PostgreSQL loads the correct last submission LSN from the offset