B 站视频分享的嵌入代码是默认自动播放的,有时安安静静的刷着网页,突然刷出一个很大的声音,吓人一跳,去关掉还要滚动网页去找,体验非常不好。
其实 B 站嵌入视频是可以关闭自动播放的,在 src 中添加 &autoplay=0
即可。
示例
获取嵌入代码
B 站默认获取的嵌入代码如下:
<iframe src="//player.bilibili.com/player.html?isOutside=true&aid=228086186&bvid=BV1ch411L7aL&cid=1111035512&p=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"></iframe>
调整代码
在 src 中添加 &autoplay=0
,再加一些样式放大播放窗口,还可以按需添加 iframe
的 sandbox
属性限制点击跳转。
<div style="position: relative; padding: 28.1% 45%;">
<iframe src="//player.bilibili.com/player.html?isOutside=true&aid=228086186&bvid=BV1ch411L7aL&cid=1111035512&p=1&autoplay=0" frameborder="no" scrolling="no" allowfullscreen="true" sandbox="allow-top-navigation allow-same-origin allow-forms allow-scripts" style="position: absolute; width: 100%; height: 100%; left: 0; top: 0;" ></iframe>
</div>