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:
|
<<: Write a formal blog using XHTML CSS
>>: Windows Server 2016 Quick Start Guide to Deploy Remote Desktop Services
Last night, I was looking at an interview question...
Requirement: The page needs to display an image, ...
at at + time at 17:23 at> touch /mnt/file{1..9...
There are many ways to generate a global ID. Here...
Table of contents mysql log files binlog Binlog l...
When using Oracle database for fuzzy query, The c...
Table of contents Linux environment variables and...
Table of contents Understanding SQL Understanding...
Introduction to MySQL Window Functions MySQL has ...
This article describes the MySQL integrity constr...
1. Download the MySQL 5.7 installation package fr...
This article introduces Docker+Jenkins automatic ...
Table of contents Overview Form validation withou...
Table of contents 1. Instructions for use 2. Prep...
This article example shares the specific code of ...