当前位置:网站首页>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>
看个轮廓就可以了哈,反正两个都不会缩放,今天就到这里!
边栏推荐
猜你喜欢
Debezium series: record the messages parsed by debezium and the solutions after the MariaDB database deletes multiple temporary tables
aggregate
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
Redis cluster simulated message queue
【obs】QString的UTF-8中文转换到blog打印 UTF-8 char*
Go language | 02 for loop and the use of common functions
2023年深圳市绿色低碳产业扶持计划申报指南
Millimeter wave radar human body sensor, intelligent perception of static presence, human presence detection application
Build your own website (16)
【无标题】
随机推荐
字节跳动Dev Better技术沙龙成功举办,携手华泰分享Web研发效能提升经验
C#应用程序界面开发基础——窗体控制(6)——菜单栏、工具栏和状态栏控件
建议收藏,我的腾讯Android面试经历分享
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (半柔性对接 AutoDock)
aggregate
id选择器和类选择器的区别
Let's talk about threadlocalinsecurerandom
Android interview classic, 2022 Android interview written examination summary
Redis cluster simulated message queue
okcc呼叫中心有什么作用
c语言oj得pe,ACM入门之OJ~
Zhongang Mining: analysis of the current market supply situation of the global fluorite industry in 2022
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
40000 word Wenshuo operator new & operator delete
Is it safe for Anxin securities to open an account online?
leetcode刷题:二叉树17(从中序与后序遍历序列构造二叉树)
leetcode刷题:二叉树11(平衡二叉树)
Debezium series: modify the source code to support UNIX_ timestamp() as DEFAULT value
Go language | 03 array, pointer, slice usage
浮动元素与父级、兄弟盒子的关系