HTML页面自适应

202 字
1 分钟
HTML页面自适应

页面自适应#

<template>
<div id="app">
<router-view/>
</div>
</template>
<script>
export default {
name: 'App',
mounted(){
this.realizeFN()
},
methods:{
realizeFN() {
setTimeout(() => {
window.onresize();
}, 40);
window.onresize = function temp() {
let width = document.body.clientWidth;
let height = document.body.clientHeight;
if (width < 1000) {
return;
}
let scaleVal = width / 1920;
let mark=document.getElementById("login")
if(mark){
return
}
let contain = document.getElementById("app");
if (contain.style) {
contain.style.marginBottom = -(1080 * (1 - scaleVal)) + "px";
contain.style.height=(height/scaleVal-65)+'px'
contain.style.transform = `scale(${scaleVal})`;
}
};
},
},
created(){
}
}
</script>
<style lang="scss">
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: #2c3e50;
width: 100%;
height: 100%;
transform-origin: 0 0;
}
::-webkit-scrollbar
{
width: 3px;
height: 5px;
// display: none
}
/*定义滚动条轨道 内阴影+圆角*/
::-webkit-scrollbar-track
{
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
border-radius: 10px;
}
/*定义滑块 内阴影+圆角*/
::-webkit-scrollbar-thumb
{
border-radius: 10px;
-webkit-box-shadow: inset 0 0 6px #15B2CC;
//background-color: #15B2CC;
}
</style>

页面缩放#

function setBodyZoom() {
const width = document.body.clientWidth;
if (width == 1920) {
document.body.style.cssText = 'zoom: 1';
} else {
document.body.style.cssText = 'zoom: ' + width / 1920;
}
}

支持与分享

如果这篇文章对你有帮助,欢迎分享给更多人或打赏支持!

打赏
HTML页面自适应
https://zhangzhiwu.cn/posts/vue/html页面自适应/
作者
zZw
发布于
2024-02-23
许可协议
CC BY-NC-SA 4.0
Profile Image of the Author
zZw
看著窗外的光 分不清是路燈還是太陽
公告
欢迎来到我的博客!
分类
标签
最新动态
站点统计
文章
26
分类
10
标签
44
总字数
13,461
运行时长
0
最后活动
0 天前
站点信息
构建平台
Local
博客版本
Firefly v6.14.5
文章许可
CC BY-NC-SA 4.0