我们使用 B 站默认的嵌入代码分享视频的时候,往往存在着分辨率太小,不能自适应页面大小的问题。分享热门视频,还可能存在弹幕过多,导致观看体验不佳的问题。这篇文章将简单分享几个小技巧,分别解决 WordPress 网站分享 B 站视频时存在的分辨率太小/不能自适应页面大小/弹幕过多遮挡页面的问题。
1、让视频自适应页面大小
将以下代码添加到 WordPress 网站的 style.css 样式表中,使用 begin 主题的朋友可以直接粘贴到“主题选项——>定制风格——>自定义样式”中。
.smartideo { z-index: 0; text-align: center; background: #CCC; line-height: 0; text-indent: 0; }
.smartideo embed, .smartideo iframe { padding: 0; margin: 0; }
.smartideo .player { width: 100%; height: 500px; overflow: hidden; position: relative; }
.smartideo .player a.smartideo-play-link { display: block; width: 50px; height: 50px; text-decoration: none; border: 0; position: absolute; left: 50%; top: 50%; margin: -25px; }
.smartideo .player a.smartideo-play-link p { display: none; }
.smartideo .player .smartideo-play-button { width: 0; height: 0; border-top: 25px solid transparent; border-left: 50px solid #FFF; border-bottom: 25px solid transparent; }
.smartideo .tips { background: #f2f2f2; text-align: center; max-height: 32px; line-height: 32px; font-size: 12px; }
.smartideo .tips a { text-decoration: none; }
@media screen and (max-width:959px){
.smartideo .player { height: 450px; }
}
@media screen and (max-width:767px){
.smartideo .player { height: 400px; }
}
@media screen and (max-width:639px){
.smartideo .player { height: 350px; }
}
@media screen and (max-width:479px){
.smartideo .player { height: 250px; }
}
打开你想分享的视频,复制【嵌入代码】。
插入到文章时,代码中添加下面两个 DIV 块来引用前面的样式,如下所示:
<div class="smartideo">
<div class="player"><iframe src="//player.bilibili.com/player.html?aid=243829823&bvid=BV1Sv411i7KS&cid=209606589&page=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe></div>
</div>
添加【width="100%" height="100%"】两个属性,指定视频宽高为 100%显示。
<div class="smartideo">
<div class="player">
<iframe src="//player.bilibili.com/player.html?aid=243829823&bvid=BV1Sv411i7KS&cid=209606589&page=1" width="100%" height="100%" frameborder="no" scrolling="no" allowfullscreen="allowfullscreen"></iframe>
</div>
</div>
2、将默认分辨率设为 1080P
我们前面解决了网站嵌入 B 站视频不能自适应大小的问题,但是视频的分辨率默认只有 360P。有什么办法可以将视频的分辨率更改为默认 1080P?方法很简单,在网址那加上high_quality=1参数即可。
修改前的代码为:
<iframe src="//player.bilibili.com/player.html?aid=243829823&bvid=BV1Sv411i7KS&cid=209606589&page=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>
修改后的代码为:
<iframe src="//player.bilibili.com/player.html?aid=243829823&bvid=BV1Sv411i7KS&cid=209606589&page=1&high_quality=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>
3、去掉视频中的弹幕
同上,想去掉视频中的弹幕,在网址那加上&danmaku=0参数即可。
修改前的代码为:
<iframe src="//player.bilibili.com/player.html?aid=243829823&bvid=BV1Sv411i7KS&cid=209606589&page=1&high_quality=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>
修改后的代码为:
<iframe src="//player.bilibili.com/player.html?aid=243829823&bvid=BV1Sv411i7KS&cid=209606589&page=1&high_quality=1&danmaku=0" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>
经过以上三个步骤的修改,我们用一个视频来看一下最终的实现效果:
修改前效果:
修改后效果:
最终代码如下所示:
<div class="smartideo">
<div class="player">
<iframe src="//player.bilibili.com/player.html?aid=243829823&bvid=BV1Sv411i7KS&cid=209606589&page=1&high_quality=1&danmaku=0" width="100%" height="100%" frameborder="no" scrolling="no" allowfullscreen="allowfullscreen"> </iframe>
</div>
</div>
这很有价值,我都都想放到我的博客了。
切换失败啊???