Check if viewport zoomed

左心房为你撑大大i 提交于 2020-01-16 02:51:09

问题


Is there an easy way to check whether the user scaled the page (using pinch on mobile devices)?

Thought verge.js would help, but I don't know what I can compare viewportH with.


回答1:


You can compare the screen.width to the window.innerWidth. If the value is anything other than 1, the viewport has been zoomed.

viewportScale = screen.width / window.innerWidth;
alert(viewportScale);

References: https://developer.mozilla.org/en-US/docs/Web/API/Window.screen

https://developer.mozilla.org/en-US/docs/Web/API/window.innerWidth




回答2:


    (
        document.documentElement.clientWidth
    /   window.innerWidth
    )
>
    1

Only for mobile devices, though!



来源:https://stackoverflow.com/questions/19888098/check-if-viewport-zoomed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!