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>
相关推荐
yume_sibai23 分钟前
大屏数据可视化 - 边框红绿呼吸灯实现详解
前端·信息可视化·typescript
竹林81836 分钟前
从 ethers.js 迁移到 Viem:一个签名验证 Bug 让我彻底放弃旧爱
javascript
Hyyy1 小时前
很多Desktop都在上的Computer Use是什么
前端·llm
慢功夫1 小时前
开篇:VS Code 为什么不是一个普通 React App
前端·visual studio code
jimy11 小时前
C语言模拟对象、方法:“函数指针+结构体“复用函数指针指向的函数体
c语言·开发语言
你挚爱的强哥1 小时前
Vue2 实现 1.5s 十连击监听(连续点击若干次),封装通用可复用点击检测工具,不用 data!Vue 封装通用连击监听方法,支持自定义时长与点击次数
前端·javascript·vue.js
半个落月1 小时前
用 LangChain.js 手写一个能读写文件和执行命令的 Mini Cursor
javascript·人工智能·后端
天外天-亮2 小时前
HBuilder X 使用 uview-plus 方式
开发语言·javascript·hbuilder x·uview-plus
huashengzsj2 小时前
Shopify个人建站如何搭建独立站:从零开始的完整指南
前端·网络·人工智能
木木子222 小时前
[特殊字符] 音乐播放器——状态驱动的多媒体控制
android·开发语言·华为·php·harmonyos