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; }}支持与分享
如果这篇文章对你有帮助,欢迎分享给更多人或打赏支持!

苏公网安备32021402002558号