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>
相关推荐
风吹乱了我的头发~3 分钟前
Day31:2026年2月21日打卡
开发语言·c++·算法
范特西.i8 分钟前
QT聊天项目(6)
前端
a11177614 分钟前
水体渲染系统(html开源)
前端·开源·threejs·水体渲染
程序员小李白40 分钟前
CSS 盒子模型
前端·css·html
Zzz不能停1 小时前
单行 / 多行文本显示省略号(CSS 实现)
前端·css
xiaoxue..1 小时前
TailwindCSS:从“样式民工”到“UI乐高大师”的逆袭
前端·css·ui
蜜獾云1 小时前
JAVA面试题速记-第1期-java基础
java·开发语言
百锦再2 小时前
Java中的反射机制详解:从原理到实践的全面剖析
java·开发语言·jvm·spring boot·struts·spring cloud·kafka
没有bug.的程序员2 小时前
Gradle 构建优化深度探秘:从 Java 核心到底层 Android 物理性能压榨实战指南
android·java·开发语言·分布式·缓存·gradle
宇木灵2 小时前
C语言基础学习-X0前置
c语言·开发语言·学习