Internet Explorer innerHeight

前端 未结 5 1546
日久生厌
日久生厌 2021-02-20 12:22

How can you get the window.innerHeight in internet explorer. Thanks.

5条回答
  •  孤独总比滥情好
    2021-02-20 12:55

    In ie9, window.innerHeight and document.body.clientHeight only works when the content is higher than the document window.

    A reliable solution is to use the vw and vh css properties.

    css (easy) way :

    /* foce the content to be at 100% with css */
    html, body {
        width: 100vw;
        height: 100vh;
    }
    

    js way :

    // make a fitted htmlelement and returns its size.
    var get_ie_size=function(){
        var domtest = document.createElement('div');
        domtest.style.display="block";
        domtest.style.width="100vw";
        domtest.style.height="100vh";
        document.body.appendChild(domtest);
        var size = [domtest.offsetWidth,domtest.offsetHeight];
        document.body.removeChild(domtest);
        return size;
    };
    

提交回复
热议问题