B站視頻嵌入博客文章的自適應(yīng)代碼

廣告也精彩

在編輯博客時(shí),需要嵌入B站視頻,但復(fù)制B站給的嵌入代碼后會(huì)發(fā)現(xiàn)寬度和高度屬性都沒有,無法自適應(yīng)div,單獨(dú)設(shè)置寬度和高度也不太完美,如何解決這個(gè)問題?

用下面這段代碼,只需要替換aid即可:

<iframe id="spkj" src="https://player.bilibili.com/player.html?aid=900831672&bvid=BV1VN4y1K76x&cid=839712989&page=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" width=100% sandbox="allow-top-navigation allow-same-origin allow-forms allow-scripts"> </iframe>
<script type="text/javascript">  
document.getElementById("spkj").style.height=document.getElementById("spkj").scrollWidth*0.76+"px";
</script>

這段代碼可以使嵌入文章的B站視頻自適應(yīng)div的寬度,效果如下:

其中的代碼:

sandbox="allow-top-navigation allow-same-origin allow-forms allow-scripts"

可以使點(diǎn)擊的彈出鏈接失效,避免外鏈跳出本站,如果不需要這個(gè)效果,刪掉這段代碼即可。

收藏本站,已備不時(shí)之需吧。

? 版權(quán)聲明

相關(guān)文章

暫無評(píng)論

none
暫無評(píng)論...