当前位置: 首页 > article >正文

vue前端可视化大屏页面适配方案

参考了其他博主的代码,但发现会有滚动条,并且居中的位置不太对,所以改了一下css,修复了这些问题,直接上代码

<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>


http://www.kler.cn/a/552376.html

相关文章:

  • torch使用心得
  • pyqt 调用颜色选择器
  • 蚁剑(AutSword)的下载安装与报错解决
  • 【git】通过 rebase 合并分支
  • Python高级语法之urllib
  • MAVSDK - Custom Mavlink处理
  • 【笔记】linux离线部署Ollama+Deepseek r1+open webui
  • 本地 Ollama 部署 Deepseek R1 并使用 Spring AI Alibaba 构建 Chat 应用示例
  • STM32 HAL库 UART串口发送数据实验
  • 华为交换机trunk简介配置
  • POI优化Excel录入
  • Node.js 中 morgan 依赖详解
  • 使用iOS个人声音与SoVITS训练个人AI语音(10分钟快速上手)
  • Linux上部署Java项目-通过sh脚本启动
  • Day01 【苍穹外卖】环境搭建与前后端联调
  • MySQL 面试系列:MySQL 事务的面试题总结
  • 芯麦GC1808立体声ADC芯片解析:高性价比与全集成音频采集方案
  • 【Java】分布式锁Redis和Redisson
  • PHP Web 开发基础
  • [数据结构]红黑树,详细图解插入