vuepress使用iframe组件嵌入bilibili视频
自制iframe固定比例嵌入bilibili视频
好朋友毛毛的作品,我拿来测试下bilibili视频的嵌入情况。请大家踊跃投币。视频AV号:av90992146。
markdown代码:
<iframeVideo ihtml="https://player.bilibili.com/player.html?aid=90992146&cid=155380603&page=1&danmaku=0&high_quality=1"></iframeVideo >
<iframeVideo ihtml="https://player.bilibili.com/player.html?aid=90992146&cid=155380603&page=2&danmaku=0&high_quality=1"></iframeVideo >
1
2
2
vue组件代码:
提示
以下代码实现了宽高定比例并自适应高度的iframe嵌入方式,原生的iframe组件需要自行输入高宽。
<!--docs/.vuepress/components/iframeComp.vue-->
<template>
<iframe class="video-iframe" width="100%" v-resize="{ log: true }" frameborder="no" scrolling="no" seamless="" allowfullscreen="allowfullscreen" :src="ihtml"></iframe>
</template>
<script>
export default {
props: {
ihtml: {
type: String
}
},
mounted(){
function changeVideoIframe(){
const video = document.getElementsByClassName('video-iframe');
const width = document.getElementsByClassName('video-iframe')[0].scrollWidth;
for(let i = 0;i<video.length;i++){
video[i].style.height = width*0.75+'px'
}
}
changeVideoIframe()
window.onresize = function(){changeVideoIframe()}
}
}
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
bilibili参数说明:
参数名 | 备注 |
---|---|
page | 第几p视频 |
danmaku | 弹幕是否开启 |
high_quality | 是否高清晰度 |
上次更新: 2024/03/11, 23:50:27