大屏页面自适应

    window.onresize = () => {
        return (() => {
            myfunction()
        })()
    }
    myfunction()

    function myfunction() {
        var bodys = document.getElementsByTagName("body")[0]
        var w = window.innerWidth
        var h = window.innerHeight
        var rr = bodys.scrollWidth
        var l = w / 1920
        var heights = h / 1080
        var ratio;
        if (l < heights) {
            ratio = l
        } else {
            ratio = heights
        }
        // margin-left:"+(w - (1920*heights))/2+"px !important;
        bodys.style.cssText = "width:1920px;height:1080px;margin-left:" + (w - (1920 * ratio)) / 2 + "px !important;transform: scale(" + ratio + ");transform-origin: left top;"
    }

你可能感兴趣的:(js)