其他分享
首页 > 其他分享> > html如何设置数据大屏

html如何设置数据大屏

作者:互联网

为了适应各种屏幕的效果,页面采用了缩放功能,按照设定好的比例全屏铺满。

html

<body>
    <div class="box" id="body">
        <p>按F11全屏显示</p>
        <div class="bottom">
            <p>底部全屏可见</p>
        </div>
    </div>
</body>

js

页面缩放

   function windowResize() {
            let cw = 1920,ch = 1080;
            let body = document.getElementById('body');
            body.style.width = `${cw}px`;
            // 窗口宽高
            let w = window.innerWidth;
            // 缩放比例
            let wr=  w / cw;
            body.style.transform = `scale(${wr})`;
            // 因为scale是以body的原中心点为基准进行缩放,所以缩放之后需要调整外边距,使其位于窗口的中心位置
            body.style.overflow= 'hidden';
        }

取消缩放

function cancelWindowResize() {
            let body = document.getElementById('body');
            body.style.transform = 'none';
            body.style.margin = '0';
            body.style.width = '100%';
            body.style.height = '100%';
}

页面初始化

window.onload = function () {
        windowResize();
        window.addEventListener('resize', windowResize);
        return () => {
            cancelWindowResize();
            window.removeEventListener('resize', windowResize);
        };
}

css

 * {
        margin: 0px;
        padding: 0px;
        width: 100%;
        height: 100%;
    }
    body {
        position: relative;
    }
    .box {
        font-size: 2rem;
        text-align: center;
        background: burlywood;
        height: 100%;
        width: 100%;
        position: fixed !important;
        top: 0;
        left: 0;
        transform-origin: left top;
    }
    .ddd {
        height: 100px;
        width: 100px;
        background: beige;
    }
    .bottom {
        position: absolute;
        bottom: 0px;
        width: auto;
        height: auto;
    }

 

标签:body,style,缩放,100%,height,width,html,设置,大屏
来源: https://www.cnblogs.com/bigffish/p/16423927.html