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>
相关推荐
xiaoyan20152 分钟前
2026最新款Vite7+Vue3+DeepSeek-V3.2+Markdown流式输出AI会话
vue.js·openai·deepseek
拼好饭和她皆失4 分钟前
c++---快速记忆stl容器
开发语言·c++
黎雁·泠崖8 分钟前
C 语言字符串高阶:strstr/strtok/strerror 精讲(含 strstr 模拟实现)
c语言·开发语言
PeaceKeeper79 分钟前
Objective-c的内存管理以及Block
开发语言·macos·objective-c
WebRuntime9 分钟前
问世间,exe是何物?直教AI沉默、Web寡言(1)
javascript·c#·.net·web
2501_9369603610 分钟前
c语言期末速成8——文件
c语言·开发语言
小鸡脚来咯10 分钟前
RabbitMQ详解(从入门到实战)
开发语言·后端·ruby
岁月宁静12 分钟前
一个 AI 聊天功能,背后至少 8 个你没想到的工程细节
前端·vue.js·aigc
唐装鼠15 分钟前
Rust Box<T> 和引用(deepseek)
开发语言·rust
计算机学姐17 分钟前
基于php的非物质文化遗产推广系统
开发语言·vue.js·mysql·tomcat·php·postman