Android browser's screen.width, screen.height & window.innerWidth & window.innerHeight are unreliable

后端 未结 8 1537
一个人的身影
一个人的身影 2020-12-05 02:53

I\'m working on a web app that is targeted to browsers on desktop, tablet and smartphone.

The web app has a light box implemented using Colorbox with an iframe

8条回答
  •  情歌与酒
    2020-12-05 03:11

        var throttle = (function () {
            var timer;
    
            return function (fn, delay) {
                clearTimeout(timer);
                timer = setTimeout(fn, delay);
          };
        })(),
    
    
        var callback = function (w, h) {
            alert(w + ' ' + h);
        }
    
    
        window.onresize = throttle(function () {
            width = Math.min(window.innerWidth, window.outerWidth);
            height = Math.min(window.innerHeight, window.outerHeight);
    
            callback(width, height);
        }, 60);
    

提交回复
热议问题