How to detect page zoom level in all modern browsers?

后端 未结 28 1776
慢半拍i
慢半拍i 2020-11-21 05:27
  1. How can I detect the page zoom level in all modern browsers? While this thread tells how to do it in IE7 and IE8, I can\'t find a good cross-browser solution.

28条回答
  •  执念已碎
    2020-11-21 06:07

    I have this solution for mobile only (tested with Android):

    jQuery(function($){
    
    zoom_level = function(){
    
        $("body").prepend('
    '); var ratio = $("body .overlay:eq(0)").outerWidth() / $(window).width(); $("body .overlay:eq(0)").remove(); return ratio; } alert(zoom_level()); });

    If you want the zoom level right after the pinch move, you will probably have to set a little timeout because of the rendering delay (but I'm not sure because I didn't test it).

提交回复
热议问题