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>
相关推荐
许彰午2 分钟前
34-安全复盘96个问题
前端·vue.js·安全
luj_176810 分钟前
一线一区一变破解人盯人防守密码
开发语言·网络·c++·经验分享·算法
妙码生花21 分钟前
PHP 各框架下和 Go 的性能比较
前端·后端·go
名字还没想好☜29 分钟前
Python 字符编码实战:encode/decode、UnicodeDecodeError 与 open 的 encoding 坑
开发语言·后端·python·编程语言
萧瑟余晖30 分钟前
持久层选型与框架对比详解
开发语言·架构
Csvn31 分钟前
TypeScript 类型性能:让类型体操不再卡死编译器
前端
CodeStats34 分钟前
【Java 类加载器】Java 类加载器完整体系深度拆解(上):从 JVM 启动到双亲委派模型
java·开发语言·jvm·classloader·双亲委派
万少42 分钟前
等不到 Apple 的折叠 iPhone,我用 DeepV4.1Flash + workBuddy 一句话自己造了一台
前端·javascript·后端
软件黑马王子42 分钟前
24.Editor 资源加载:主要作用和基本原理
开发语言·前端框架·c#
梦曦i1 小时前
uni-router v0.2.0重磅发布:全链路拦截+重复导航优化
前端·uni-app