我试图在 youtube iframe 嵌入代码上放置一个 div,但它不起作用。 有什么想法吗?
我的代码是:
$('#iframe').prepend("<div style='width:800px; height:450px; background-color:#fff;'></div");
和经典的 youtube iframe:
<iframe width="800" height="450" src="//www.youtube.com/embed/mllXxyHTzfg?rel=0" frameborder="0" allowfullscreen></iframe>
最佳答案
如果你想要一个 Javascript 解决方案:
function coverVideo(){
// Create an empty div
var cover = $("<div></div>").appendTo("body");
cover.css({
// Position directly over the iframe
position: "absolute",
top: $("#iframe").offset().top,
left: $("#iframe").offset().left,
// Style as you like
width: "800px",
height: "450px",
background: "#fff"
});
}
关于javascript - 找到 youtube iframe 并在其上附加一个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25591631/