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

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>

相关文章:

  • 日本90年代经济泡沫初期是什么情况?
  • 面试经典150题——字典树
  • 深入探索xtquant:账户信息查询的全面指南
  • WPS中如何批量上下居中对齐word表格中的所有文字
  • DeepSeek的深度解析:由来、研发过程、公司背景、优势、劣势与总结
  • WSL Ubuntu 安装 CUDA 教程
  • 嵌入式AI革命:DeepSeek开源如何终结GPU霸权,开启单片机智能新时代?
  • 芯谷 D2761:专为扬声器保护设计的音频限幅器
  • 网络将内网服务转换到公网上
  • vue学习10
  • Windows 图形显示驱动开发-WDDM 2.0 -GpuMmu 寻址方式
  • 蓝桥杯单片机组第十三届初赛试题-程序题(第2批)
  • 我用AI做数据分析之数据清洗
  • 【python】连接Jira获取token以及jira对象
  • C++-----------酒店客房管理系统
  • Maven下载安装IDEA使用MavenJava在pom.xml配置教程
  • Python--多线程
  • 探索ChatGPT背后的前端黑科技
  • 机器学习数学基础:26.随机变量分布详解
  • Python用PyMC3马尔可夫链蒙特卡罗MCMC对疾病症状数据贝叶斯推断
  • 推广网站企业/网络营销方法
  • 武汉万网站制作 费用/什么是百度竞价
  • wordpress大前端2.0/搜索引擎优化网站
  • 湖南省人民政府热线电话/seo简单优化
  • 四川省建设厅网站打不开/百度搜索引擎首页
  • 学校英语网站栏目名称/广告商对接平台