大屏项目缩放问题解决方案

该代码段是用于计算并调整基于设计稿尺寸的内容在不同窗口比例下的缩放方式。当窗口宽度与高度比例大于设计稿比例时,内容按高度缩放;否则,按宽度缩放。使用`calcRate`函数计算放大倍数,并在窗口大小改变时更新(`resize`事件)。Vue组件结构中包含多个子组件,如`top-header`,`content-left`,`content-main`等。
摘要由CSDN通过智能技术生成

原有设计稿比例

baseWidth: 1920, // 设计稿尺寸
baseHeight: 1080,  // 设计稿尺寸
baseProportion: 0, // 比例

缩放与改变

 // 计算放大倍数
    calcRate() {
      const contentRef = this.$refs.contentRef;
      if (!contentRef) return;
      // 当前宽高比
      const currentRate = parseFloat((window.innerWidth / window.innerHeight).toFixed(2));
      if (currentRate > this.baseProportion) {
        // 表示更宽
        this.scale.width = ((window.innerHeight * this.baseProportion) / this.baseWidth).toFixed(2);
        this.scale.height = (window.innerHeight / this.baseHeight).toFixed(2);
        contentRef.style.transform = `scale(${this.scale.width}, ${this.scale.height}) translate(-50%, -50%)`;
      } else {
        // 表示更高
        this.scale.height = ((window.innerWidth / this.baseProportion) / this.baseHeight).toFixed(2);
        this.scale.width = (window.innerWidth / this.baseWidth).toFixed(2);
        contentRef.style.transform = `scale(${this.scale.width}, ${this.scale.height}) translate(-50%, -50%)`;
      }
    },
    // 屏幕大小改变更新倍数
    resize() {
      clearTimeout(this.scaleTime)
      this.scaleTime = setTimeout(() => {
        this.calcRate()
      }, 0)
    }

生命周期调用

 mounted() {
    this.calcRate()
    this.resize()
    window.addEventListener('resize', this.resize);
    // window.addEventListener('keydown', this.toggleFullscreen, true)
  },

盒子

<div class="trans-common" ref="contentRef">
        <top-header />
        <div class="main-content">
          <div class="lr-box">
            <content-left @toNews="toNews" :psDic="psDic"></content-left>
          </div>
          <div class="c-box">
            <!-- 总控台 -->
            <!-- <content-main @toTable="toTable" @toPeoInfo="toPeoInfo"></content-main> -->
            <content-main @toTable="toTable" @toPeoInfo="toPeoInfo" @toGis="toGis"></content-main>
          </div>
          <div class="lr-box">
            <content-right :psDic="psDic"></content-right>
          </div>
          <base-table :show="showTable" @toTable="toTable" @toPeoInfo="toPeoInfoSearch" @close="showTable = false">
      </base-table>
      <news v-if="showNews" :show="showNews" @close="showNews = false"></news>
      <peo-info v-if="showPeoInfo" :show="showPeoInfo" @tomapList="tomapList" @close="showPeoInfo = false"></peo-info>
      <info-gis v-if="showInfoGis" :show="showInfoGis" @close="showInfoGis = false"></info-gis>
      <!-- <Map v-if="mapList" :show="mapList" @close="mapList = false"></Map> -->
      <RouteMap v-if="routemapShow" :show="routemapShow" @close="mapShow = false"></RouteMap>
        </div>
        
      </div>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值