<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>vue全屏页面内容等比缩放</title>
<script src="https://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
body,
html {
width: 100%;
height: 100%;
}
#app {
width: 100%;
height: 100%;
overflow: hidden;
background: yellowgreen;
}
.box {
width: 1920px;
height: 1080px;
background: pink;
transform-origin: center top 0px;
position: relative;
left: 50%;
margin-left: -960px;
}
</style>
</head>
<body>
<script src="https://www.jq22.com/jquery/vue.min.js"></script>
<script src="https://s1.pstatp.com/cdn/expire-1-M/vue/2.2.2/vue.min.js"></script>
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
<h3>调整浏览器窗口大小查看效果</h3>
<div id="app">
<div
class="box"
:style="{
'transformOrigin':'center top',
'transform':`scale(${scalseNum},${scalseNum})`,'-webkit-transform':`scale(${scalseNum},${scalseNum})`,'-moz-transform':`scale(${scalseNum},${scalseNum})`,'-o-transform':`scale(${scalseNum},${scalseNum})`,'-ms-transform':`scale(${scalseNum},${scalseNum})`
}"
>
<h1>缩放的盒子 比例是:{{scalseNum}}</h1>
</div>
</div>
<script>
new Vue({
el: "#app",
data: {
scalseNum: 1, //缩放比例
},
mounted() {
//计算缩放比例
this.resize_window();
window.addEventListener("resize", () => {
this.resize_window();
});
},
methods: {
//计算缩放比例
resize_window() {
let w_height = Number(document.documentElement.clientHeight / 1080);
this.scalseNum = w_height;
},
},
});
</script>
</body>
</html>
vue全屏页面内容等比缩放
最新推荐文章于 2024-09-10 08:00:00 发布