<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
.container{
width: 100vw;
height: 100vh;
background-image: url(http://8.222.176.28/assets/bg-16c5dcec.png) ;
background-repeat: no-repeat;
background-size: cover;
}
.box{
position: fixed;
width: 1920px;
height: 1080px;
background-color: red;
transform-origin: left top;
top: 50%;
left: 50%;
}
.top{
width: 100px;
height: 100px;
margin-bottom: 100px;
margin-left: 50px;
background-color: hotpink;
}
.bottom{
width: 100px;
height: 100px;
margin-left: 50px;
background-color: greenyellow;
}
</style>
</head>
<body>
<div class="container">
<div class="box">
<div class="top">top</div>
<div class="bottom">bottom</div>
</div>
</div>
</body>
<script>
// 控制数据大屏放大与缩小
let box=document.querySelector('.box');
box.style.transform=`scale(${getScale()}) translate(-50%,-50%)`;
// 计算缩放比例
function getScale(w=1920,h=1080){
const ww=window.innerWidth/w;
const wh=window.innerHeight/h;
return ww<wh?ww:wh
};
window.onresize=()=>{
box.style.transform=`scale(${getScale()}) translate(-50%,-50%)`;
}
</script>
</html>