使用Javascript / Jquery禁用桌面Web浏览器中页面的缩放 [英] Disable zooming of the page in desktop web browsers using Javascript/Jquery

查看:189
本文介绍了使用Javascript / Jquery禁用桌面Web浏览器中页面的缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:





var obj=document.body;  // obj=element for example body
// bind mousewheel event on the mouseWheel function
if(obj.addEventListener)
{
    obj.addEventListener('DOMMouseScroll',mouseWheel,false);
    obj.addEventListener("mousewheel",mouseWheel,false);
}
else obj.onmousewheel=mouseWheel;

function mouseWheel(e)
{
    // disabling
    e=e?e:window.event;
    if(e.ctrlKey)
    {
        if(e.preventDefault) e.preventDefault();
        else e.returnValue=false;
        return false;
    }
}

我正在开发一个网络应用程序,所有ui元素将如果用户放大/缩小,则输入顺序不正确。那么,有什么方法可以阻止它吗?我想到了一些方法,但是可能吗?

I am developing a web app and all ui element will be not in a correct order if user zoom in / zoom out . So, are there any way to prevent it? I have think of some way to do it but is it possible ?

1)获取用户的屏幕分辨率。当窗口大小改变(宽度或高度)时,将窗口宽度/高度返回到屏幕宽度/高度。

1) Get the screen resolution of the user. When the window size is change (either width or height), return the window width/height to screen width /height.

2)将鼠标滚动事件或键盘事件绑定为空。 (请参阅上面的演示代码),但如果用户点击浏览器并选择放大怎么办?

2) bind the mouse scroll event or keyboard event to nothing. (Refer to above demo code) , but what if the user click on the browser and select zoom in ?

谢谢

推荐答案

    var zoomlevel=1;

    $("body").dblclick(function(ev) {
        zoomlevel = zoomlevel == 1 ? 2 : 1;



        $(this).css({
            "-moz-transform":"scale("+zoomlevel+")",
            "-webkit-transform":"scale("+zoomlevel+")",
            "-o-transform":"scale("+zoomlevel+")",
            "-ms-transform":"scale("+zoomlevel+")"
        });


    });

这篇关于使用Javascript / Jquery禁用桌面Web浏览器中页面的缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆