vue中缩放比的使用

大屏适用性比较大,后台系统不推荐

抽组件,scaleScreen

<template>
  <div
    id="screen"
    :style="{
      width: `${style.width}px`,
      height: `${style.height}px`,
      transform: `${style.transform}`,
    }"
  >
    <slot ></slot>
  </div>
</template>

<script>
export default {
  name: "scaleScreen",
  props: {},
  data() {
    return {
      style: {
        width: "1920",
        height: "1080",
        transform: "scaleY(1) scaleX(1) translate(-50%, -50%)",
      },
    };
  },
  methods: {
    getScale() {
      const w = window.innerWidth / this.style.width;
      const h = window.innerHeight / this.style.height;
      return { x: w, y: h };
    },
    setScale() {
      const scale = this.getScale();
      this.style.transform =
        "scaleY(" + scale.y + ") scaleX(" + scale.x + ") translate(-50%, -50%)";
    },
  },
  mounted() {
    const that = this;
    that.setScale();
    /* 窗口改变事件 */
    window.addEventListener("resize", function () {
      console.log("窗口发生变化");
      that.setScale();
    });
  },
};
</script>

<style lang="scss" scoped>
#screen {
  z-index: 100;
  transform-origin: 0 0;
  position: fixed;
  left: 50%;
  top: 50%;
  transition: 0.3s;
}
</style>

使用时,用组件包裹就可以

<template>
  <scale-screen>
    
    
  </scale-screen>
</template>

相关推荐

  1. vue使用

    2024-07-17 17:36:05       21 阅读
  2. vue滚轮事件

    2024-07-17 17:36:05       53 阅读
  3. Qt获取屏幕DPI

    2024-07-17 17:36:05       72 阅读
  4. C#使用Matrix类对Dicom图像

    2024-07-17 17:36:05       65 阅读
  5. 小程序使用wx.previewImage实现图片预览与

    2024-07-17 17:36:05       43 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-17 17:36:05       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-17 17:36:05       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-17 17:36:05       58 阅读
  4. Python语言-面向对象

    2024-07-17 17:36:05       69 阅读

热门阅读

  1. Linux指令&&ros学习&&python深度学习&&bug学习笔记

    2024-07-17 17:36:05       19 阅读
  2. 中文科技核心论文发表

    2024-07-17 17:36:05       19 阅读
  3. MPS 后端

    2024-07-17 17:36:05       24 阅读
  4. C# ForgettableKnowledge

    2024-07-17 17:36:05       20 阅读
  5. HarmonyOS 如何下载网络图片

    2024-07-17 17:36:05       23 阅读
  6. Postman 接口测试详解

    2024-07-17 17:36:05       19 阅读