首页 > 其他 > 详细

一屏显示--动态分配每个区域的高度

时间:2019-11-11 22:43:40      阅读:93      评论:0      收藏:0      [点我收藏+]

在mouted中去获取页面的高度(clientHeight)  然后给每个区域动态分配值

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <!-- 引入样式 -->
        <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
        <!-- 引入组件库 -->
        <script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.min.js"></script>
        <!-- 引入Vue -->
        <script src="https://unpkg.com/element-ui/lib/index.js"></script>
        <style>
        html,body{
            height: 100%;
            width: 100%;
            margin: 0;
        }
            
   .el-row {
    padding: 0;
    &:last-child {
      margin-bottom: 0;
    }
  }
  .el-col {
    border-radius: 4px;
  }

  .grid-content {
    border-radius: 4px;
  }

  .aa,.bb,.cc,.dd{
    
  }
  .aa{
      background: #0099FF;
  }
   .bb{
        background: #FFC0CB;
  }
   .cc{
        background: darkmagenta;
  }
   .dd{
        background: sienna;
  }
  
  #app{
      height: 100%;
  }

        </style>
    </head>
    <body>

        <div id="app">
            
            <el-row class="aa" id="fullheight1">
                <el-col :span="24">
                    <div class="grid-content bg-purple-dark">11111</div>
                </el-col>
            </el-row>
            
            <el-row class="bb" id="fullheight2">
                <el-col :span="12">
                    <div class="grid-content bg-purple">2222222</div>
                </el-col>
                <el-col :span="12">
                    <div class="grid-content bg-purple-light">333333</div>
                </el-col>
            </el-row>
            
            <el-row class="cc" id="fullheight3">
                <el-col :span="8">
                    <div class="grid-content bg-purple">444444</div>
                </el-col>
                <el-col :span="8">
                    <div class="grid-content bg-purple-light">333333</div>
                </el-col>
                <el-col :span="8">
                    <div class="grid-content bg-purple">333333</div>
                </el-col>
            </el-row>
            
            <el-row class="dd" id="fullheight4">
                <el-col :span="6">
                    <div class="grid-content bg-purple">33333</div>
                </el-col>
                <el-col :span="6">
                    <div class="grid-content bg-purple-light">33333</div>
                </el-col>
                <el-col :span="6">
                    <div class="grid-content bg-purple">33333</div>
                </el-col>
                <el-col :span="6">
                    <div class="grid-content bg-purple-light">33333</div>
                </el-col>
            </el-row>

        </div>

    </body>

 

    <script>
        new Vue({
            el: ‘#app‘,
            data() {
                return {
                    pingheight:""
                };
            },
          
            mounted(){
              this.pingheight=document.documentElement.clientHeight;//获取屏幕的高度
              document.getElementById("fullheight1").style.height=Math.floor(this.pingheight/4)+"px";
              document.getElementById("fullheight2").style.height=Math.floor(this.pingheight/4)+"px";
              document.getElementById("fullheight3").style.height=Math.floor(this.pingheight/4)+"px";
              document.getElementById("fullheight4").style.height=Math.floor(this.pingheight/4)+"px";
            },
  
        })
    </script>

 

技术分享图片

 

 

 

 

 

一屏显示--动态分配每个区域的高度

原文:https://www.cnblogs.com/IwishIcould/p/11838917.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!