我有一种情况我想在我的网站上添加一个vimeo播放器,在播放器上方我需要显示一个图像。当点击图像我想要vimeo播放器播放。 到目前为止,我做了一点,我设法让页面上的vimeo播放器点击图像。但现在我需要手动播放它。任何人告诉我如何在图像点击上自动播放它? 我已经完成了一些代码,我在这里粘贴它
<script type="text/javascript">
function imgClick() {
var video = '<iframe src="http://player.vimeo.com/video/36302746?title=0&byline=0&portrait=0" width="400" height="225" frameborder="0" webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen=""> </iframe>';
document.getElementById("vPlayer").innerHTML = video;
}
</script>
答案 0 :(得分:10)
iframe不仅仅是要在innerHtml上添加它的文本,还需要将其添加为元素。因此,ether将其创建为元素,以太将其添加为标记,并在html代码上准备就绪,并且只需更改它的src和可见性。以下是如何在onfly上创建它。
function imgClick() {
var ifrm = document.createElement("IFRAME");
ifrm.setAttribute("src", "http://player.vimeo.com/video/36302746?title=0&byline=0&portrait=0");
ifrm.style.width = "400px";
ifrm.style.height = "224px";
// add rest of your values
ifrm.frameborder = 0;
document.getElementById("vPlayer").appendChild(ifrm);
return false;
}
我测试了这段代码并正常工作。请将您的图片称为onclick="return imgClick();"