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>
相关推荐
froginwe111 分钟前
SQL PRIMARY KEY(主键)
开发语言
2401_885885045 分钟前
视频短信接口集成起来复杂吗?API接入说明
开发语言·php·音视频
Thexhy7 分钟前
Java 后端完整成长路线(含项目)
java·开发语言
27669582928 分钟前
携程旅行 token1005
java·linux·前端·javascript·携程旅行·token1005·携程酒店
zopple11 分钟前
PHP与Vue.js:前后端开发的完美搭档
开发语言·vue.js·php
楚辞大魔王13 分钟前
通过ExternalTools打开编译之后的class
java·开发语言
freewlt14 分钟前
Cursor与AI编程工具崛起:前端工程师的能力模型重构与职业生存策略
前端·重构·ai编程
跟着珅聪学java16 分钟前
Java AI 开发完全教程
java·开发语言·人工智能
Magic--19 分钟前
C++ 智能指针
开发语言·c++·算法
墨雪遗痕22 分钟前
工程架构认知(三):从传统Web系统到AI大模型驱动系统
前端·人工智能·架构