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>
相关推荐
张健1156409648几秒前
QT创建线程
开发语言·qt
鲸渔1 分钟前
【C++ 输入输出】cin、cout、cerr 与格式化输出
开发语言·c++·算法
3GPP仿真实验室3 分钟前
【MATLAB源码】水声:时变信道估计仿真平台
开发语言·matlab
froginwe113 分钟前
Eclipse 关闭项目详解
开发语言
蜡台4 分钟前
Vue3 props ref router 数据通讯传输等使用记录
前端·javascript·vue.js·vue3·router·ref
Cobyte6 分钟前
从 JavaScript 的角度理解 Python 语法
前端
wjs20246 分钟前
《jQuery Validate》深度解析与应用指南
开发语言
travel_wsy7 分钟前
vue Pinia 状态管理库
前端·pinia
巫山老妖9 分钟前
📐 Embedding向量化:AI如何「理解」语义?万物皆可向量!
前端
巫山老妖9 分钟前
🤖 AI Agent智能体:从「聊天机器人」到「数字员工」的关键跨越!
前端