欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue大屏展示適配的方法

 更新時間:2021年10月25日 08:33:44   作者:weixin_43859882  
這篇文章主要為大家詳細(xì)介紹了vue大屏展示適配,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue大屏展示適配的具體代碼,供大家參考,具體內(nèi)容如下

1.utils文件夾建一個文件cv以下代碼

export function useIndex (appRef) {
  // * appRef指向最外層容器

  // * 定時函數(shù)
  let timer = null
  // * 默認(rèn)縮放值
  const scale = {
    width: '1',
    height: '1'
  }
  // * 設(shè)計稿尺寸(px)
  const baseWidth = 1920
  const baseHeight = 1080

  // * 需保持的比例(默認(rèn)2)
  // const baseProportion = parseFloat((baseWidth / baseHeight).toFixed(5))
  const baseProportion = 2
  const calcRate = () => {
    // 當(dāng)前寬高比
    const currentRate = parseFloat((window.innerWidth / window.innerHeight).toFixed(5))
    if (appRef) {
      if (currentRate > baseProportion) {
        // 表示更寬
        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 {
        // 表示更高
        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)
  }

  // 改變窗口大小重新繪制
  const windowDraw = () => {
    window.addEventListener('resize', resize)
  }

  return {
    appRef,
    calcRate,
    windowDraw
  }
}

2.app.vue結(jié)構(gòu)樣式

<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.字體大小盒子寬度直接設(shè)置px不管放大縮小都是最初的樣子,基本頁面大小不會相差太遠(yuǎn),下圖是頁面放大500倍的效果

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue路由傳參三種基本方式詳解

    vue路由傳參三種基本方式詳解

    這篇文章主要介紹了vue路由傳參三種基本方式詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-12-12
  • 搭建element-ui的Vue前端工程操作實(shí)例

    搭建element-ui的Vue前端工程操作實(shí)例

    下面小編就為大家分享一篇搭建element-ui的Vue前端工程操作實(shí)例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-02-02
  • vue實(shí)現(xiàn)購物車選擇功能

    vue實(shí)現(xiàn)購物車選擇功能

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)購物車選擇功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-01-01
  • 基于Vue實(shí)現(xiàn)卡片無限滾動動畫

    基于Vue實(shí)現(xiàn)卡片無限滾動動畫

    這篇文章主要為大家詳細(xì)介紹了如何利用Vue制作出卡片無限滾動動畫,文中的示例代碼講解詳細(xì),對我們學(xué)習(xí)有一定幫助,需要的可以參考一下
    2022-05-05
  • 最新評論