Vue large screen display adaptation method

Vue large screen display adaptation method

This article example shares the specific code for vue large screen display adaptation for your reference. The specific content is as follows

1. Create a file cv in the utils folder with the following code

export function useIndex(appRef) {
  // * appRef points to the outermost container // * Timing function let timer = null
  // * Default scaling value const scale = {
    width: '1',
    height: '1'
  }
  // * Design draft size (px)
  const baseWidth = 1920
  const baseHeight = 1080

  // * The ratio to be maintained (default 2)
  // const baseProportion = parseFloat((baseWidth / baseHeight).toFixed(5))
  const baseProportion = 2
  const calcRate = () => {
    // Current aspect ratio const currentRate = parseFloat((window.innerWidth / window.innerHeight).toFixed(5))
    if (appRef) {
      if (currentRate > baseProportion) {
        // Indicates wider scale.width = ((window.innerHeight * baseProportion) / baseWidth).toFixed(5)
        scale.height = (window.innerHeight / baseHeight).toFixed(5)
        appRef.style.transform = `scale(${scale.width}, ${scale.height}) translate(-50%, -50%)`
      } else {
        // Indicates higher scale.height = ((window.innerWidth / baseProportion) / baseHeight).toFixed(5)
        scale.width = (window.innerWidth / baseWidth).toFixed(5)
        appRef.style.transform = `scale(${scale.width}, ${scale.height}) translate(-50%, -50%)`
      }
    }
  }

  const resize = () => {
    clearTimeout(timer)
    timer = setTimeout(() => {
      calcRate()
    }, 200)
  }

  // Change the window size and redraw const windowDraw = () => {
    window.addEventListener('resize', resize)
  }

  return {
    appRef,
    calcRate,
    windowDraw
  }
}

2.app.vue structure style

<template>
  <div ref="appRef" class="main">
    <div class="layout-container">
    </div>
  </div>
</template>

<script>
import { useIndex } from '@/utils/utilsDram.js'
export default {
  mounted () {
    const { calcRate, windowDraw } = useIndex(this.$refs.appRef)
    calcRate()
    windowDraw()
  }
}
</script>
<style lang="scss" scoped>
.main {
  color: #d3d6dd;
  width: 1920px;
  height: 1080px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transform-origin: left top;

  .layout-container {
    width: 100%;
    height: 100%;
    }
   }
</style>

3. The font size and box width are directly set to px. No matter how you zoom in or out, it will remain the same as before. The basic page size will not be too different. The following figure shows the effect of zooming in 500 times.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Example code for implementing large screen adaptation on PC using vue+px2rem (rem adaptation)
  • Example of how to adapt the Vue project to the large screen

<<:  Write a formal blog using XHTML CSS

>>:  Windows Server 2016 Quick Start Guide to Deploy Remote Desktop Services

Recommend

How complicated is the priority of CSS styles?

Last night, I was looking at an interview question...

How to set up cross-domain access in IIS web.config

Requirement: The page needs to display an image, ...

Detailed explanation of scheduled tasks and delayed tasks under Linux

at at + time at 17:23 at> touch /mnt/file{1..9...

MySQL restores data through binlog

Table of contents mysql log files binlog Binlog l...

SQL fuzzy query report: ORA-00909: invalid number of parameters solution

When using Oracle database for fuzzy query, The c...

Introduction to Linux environment variables and process address space

Table of contents Linux environment variables and...

Quickly learn MySQL basics

Table of contents Understanding SQL Understanding...

Mysql8.0 uses window functions to solve sorting problems

Introduction to MySQL Window Functions MySQL has ...

Detailed explanation of mysql integrity constraints example

This article describes the MySQL integrity constr...

Detailed tutorial on installing and configuring MySQL 5.7.20 under Centos7

1. Download the MySQL 5.7 installation package fr...

Automatically build and deploy using Docker+Jenkins

This article introduces Docker+Jenkins automatic ...

How to use JavaScript strategy pattern to validate forms

Table of contents Overview Form validation withou...

Detailed explanation of MYSQL stored procedure comments

Table of contents 1. Instructions for use 2. Prep...

Vue implements button switching picture

This article example shares the specific code of ...