zoukankan      html  css  js  c++  java
  • 大屏适配

    1.创建文件


    export const echartsSize = function (size, defalteWidth = 1920) {
    const docEl = document.documentElement
    const clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth
    if (!clientWidth) return
    const fontSize = (clientWidth / defalteWidth)
    return Number((size * fontSize).toFixed(3))
    }

    // 设置系统缩放比,适配各分辨率
    export function refreshScale () {
    const baseWidth = document.documentElement.clientWidth
    const baseHeight = document.documentElement.clientHeight
    const appStyle = document.getElementById('app').style
    const bodyStyle = document.getElementsByTagName('body')[0].style
    const realRatio = baseWidth / baseHeight
    const designRatio = 16 / 9
    let scaleRate = baseWidth / 1920
    if (realRatio > designRatio) {
    scaleRate = baseHeight / 1080
    }

    /**/
    appStyle.transformOrigin = 'left top'
    appStyle.transform = `scale(${scaleRate})`
    appStyle.width = `${baseWidth / scaleRate}px`
    appStyle.height = `auto` //设置高度
    /*bodyStyle.background = `radial-gradient(#152B65, #122659 ,#030D32)`*/
    bodyStyle.background = `url('https://qiniu.dev.haiwojiamei.com/upload/meijia/20210728/cc9c326b15391925efa780367501f82e.png') no-repeat`
    bodyStyle.backgroundPosition ='center center'
    bodyStyle.backgroundSize = '100% 100%'
    }
    2.在文件中引入
    import {refreshScale} from '@/utils/util'
    3.初始化和窗口变化时执行
    mounted() {

    refreshScale();
    window.onresize=function(){
    refreshScale()
    }

    },

    3.设置
    body #app{
    1920px;
    height: 1080px;


    }





  • 相关阅读:
    BZOJ4327 : JSOI2012 玄武密码
    BZOJ4303 : 数列
    BZOJ1077 : [SCOI2008]天平
    BZOJ1829 : [Usaco2010 Mar]starc星际争霸
    BZOJ1770 : [Usaco2009 Nov]lights 燈
    BZOJ3012 : [Usaco2012 Dec]First!
    BZOJ4320 : ShangHai2006 Homework
    BZOJ4311 : 向量
    BZOJ3075 : [Usaco2013]Necklace
    BZOJ4304 : 道路改建
  • 原文地址:https://www.cnblogs.com/lixiaosong/p/15378412.html
Copyright © 2011-2022 走看看