vw vh减去px计算,根据flex进行播放窗口的2 4 6 9宫格布局

根据CSS3规范,视口单位主要包括:
1.vw:1vw等于视口宽度的1%。
2.vh:1vh等于视口高度的1%。

全屏布局需要去掉滚动条:
body::-webkit-scrollbar {
/滚动条整体样式/
width: 0px;
/高宽分别对应横竖滚动条的尺寸/
/* height: 1px; */
}

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="divport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .app {
            display: flex;
            flex-direction: row;
            flex-wrap: wrap;
            width: 100%;
            height: 100%;
        }

        body::-webkit-scrollbar {
            /*滚动条整体样式*/
            width: 0px;
            /*高宽分别对应横竖滚动条的尺寸*/
            /* height: 1px; */
        }
    </style>
    </style>
</head>

<body>
    <div class="app">
        <iframe :src='item' :style='itemStyle' v-for="(item, index) in list" :key='index'>
        </iframe>
    </div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.js"></script>
<script>
    new Vue({
        el: '.app',
        data: {
            list: ['001507', '001505', '001503', '001501', '001499'], //,'001505','001501','001499'
            itemStyle: {
                width: '',
                height: '',
                display: 'flex',
                alignItems: 'center',
                justifyContent: 'center',
                flexDirection: 'column',
                border: '1px solid #ccc',
                overFlow: 'hidden'
            },
        },
        mounted() {
            this.getWindow()
        },
        methods: {
            getWindow() {
                this.list.length > 9 ? this.list.length = 9 : this.list.length
                this.list = this.list.map(item =>
                    `http://qingdao.czczh.cn/pc/main/sub/car_video/index.html?camindex=${item}&server=1`)

                let len = this.list.length
                if (len == 1) {
                    //vw-px vh-px
                    this.itemStyle.width = 'calc(100vw - 4px)'
                    this.itemStyle.height = 'calc(100vh - 4px)'
                } else if (len > 1 && len <= 2) {
                    this.itemStyle.width = 'calc(50vw - 2px)'
                    this.itemStyle.height = 'calc(100vh - 2px)'
                } else if (len > 2 && len <= 4) {
                    this.itemStyle.width = 'calc(50vw - 2px)'
                    this.itemStyle.height = 'calc(50vh - 2px)'
                } else if (len > 4 && len <= 6) {
                    this.itemStyle.width = 'calc(33.3vw - 2px)'
                    this.itemStyle.height = 'calc(50vh - 2px)'
                } else if (len > 6 && len <= 9) {
                    this.itemStyle.width = 'calc(33.3vw - 4px)'
                    this.itemStyle.height = 'calc(33.3vh - 4px)'
                }
            },
        }
    })
</script>

</html>
posted @ 2021-09-27 10:04  赵辉Coder  阅读(461)  评论(0编辑  收藏  举报