vue使用海康视频web插件如何实现自适应

如果要实现自适应的话,就需要在不同的分辨率内设置不同的宽度和高度,可以监听当前屏幕的宽度和高度(可视区域的宽高),划分不同的显示阶段

通过设置父级元素的宽度和高度实现子级视频的自适应

index.vue

<template>
    <div class="content"> 
        <Videoplayer ref="player"
                :windowWidth="windowWidth"
                :windowHeight="windowHeight"></Videoplayer>
    </div>
</tempalte>

<script>
import Videoplayer from "@/xxxxx"
export default {
    components: {
        Videoplayer
    },
    data() {
        return {
            windowWidth: 0,
            windowHeight: 0,
        }
    },
    mounted() {
        window.addEventListener("resize", this.handleResize);
    },
    methods: {
        handleResize() {
            // 在这里根据窗口大小进行操作,例如自动调整内容的大小
            // 设置数据属性来记录窗口的当前状态
            let contentWidth =
                document.getElementsByClassName("content")[0].offsetWidth;
            this.windowWidth = contentWidth
            let contentHeight =
                document.getElementsByClassName("content")[0].offsetHeight;
            this.windowHeight = contentHeight
            console.log(contentWidth, "contentWidth");
            console.log(contentHeight, "contentHeight");
        }
    }
}

<script>

<style scoped>
.content {
    width: 100%;
    height: 400px;
}
@media only screen and (max-width: 1746px) {
    .content {
        height: 350px;
    }
}
@media only screen and (max-width: 1546px) {
    .content {
        height: 300px;
    }
}
@media only screen and (max-width: 1280px) {
    .content {
        height: 250px;
    }
}
</style>

Videoplayer.vue

在文件中接收"windowWidth","windowHeight",然后调用更改尺寸的方法,并在监听的时候也设置尺寸

注意在initPlugin()方法中也需要设置尺寸

以及initBtn()方法中也设置尺寸

这样就可以实现在不同的范围内自适应视频的宽度和高度

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值