vue前端可视化大屏页面适配方案

参考了其他博主的代码,但发现会有滚动条,并且居中的位置不太对,所以改了一下css,修复了这些问题,直接上代码

javascript 复制代码
<template>
<div class="ScaleBoxA">
    <div
      class="ScaleBox"
      ref="ScaleBox"
      :style="{
        width: width + 'px',
        height: height + 'px',
      }"
    >
         <!--  内容  -->
     </div>
</div>
</template>
<script>
export default {
   name: 'index',
   data() {
    return {
      scale: 0,
      width: 1920,
      height: 1080,
     }
    }, 
   methods: {
    getScale() {
      const { width, height } = this
      const wh = window.innerHeight / height
      const ww = window.innerWidth / width
      return ww < wh ? ww : wh
    },
    setScale() {
      this.scale = this.getScale()
      if (this.$refs.ScaleBox) {
        this.$refs.ScaleBox.style.setProperty('--scale', this.scale)
      }
    },
    debounce(fn, delay) {
      const delays = delay || 500
      let timer
      return function () {
        const th = this
        const args = arguments
        if (timer) {
          clearTimeout(timer)
        }
        timer = setTimeout(function () {
          timer = null
          fn.apply(th, args)
        }, delays)
      }
    },
  },
  mounted() {
    this.setScale()
    window.addEventListener('resize', this.debounce(this.setScale))
  },
}
<style lang="scss" scoped>
#ScaleBox {
  --scale: 1;
}
.ScaleBoxA {
  top: 0;
  width: 100vw;
  height: 100vh;
  position: fixed;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ScaleBox {
  transform: scale(var(--scale));
  display: flex;
  flex-direction: column;
  transform-origin: 960px 540px;
  transition: 0.3s;
  z-index: 999;
}
</style>
相关推荐
ShiJiuD6668889993 分钟前
外卖项目总结下 (前端板块)
前端
daols887 分钟前
vue vxe-table 复制数据到 Excel:支持带表头复制
vue.js·excel·vxe-table
聆风吟º8 分钟前
【Python编程日志】Python基础数据类型完整梳理
开发语言·python·数据类型
liming49515 分钟前
Maven中央库迁移
服务器·前端·maven
keykey6.20 分钟前
逻辑回归:从回归到分类
开发语言·人工智能·机器学习
喵星人工作室22 分钟前
C++火影忍者1.1.8
开发语言·c++·游戏
shchojj23 分钟前
ChatGPT Prompt Engineering for Developers - Expanding
开发语言·python·prompt
凡人叶枫26 分钟前
Effective C++ 条款26:尽可能延后变量定义式的出现时间
linux·开发语言·c++·effective c++
努力的lpp26 分钟前
渗透主流工具完整参数手册(sqlmap、Nmap、Hydra、Dirsearch、Xray)
javascript·网络协议·测试工具·安全·http·工具
problc29 分钟前
用 JavaScript 打开中国的版式文档:@sharp9/ofdjs 诞生记
开发语言·javascript·ecmascript