视频通过javascript被隐藏,但已经开始播放(自动播放模式),即使是's不可见
video gets hidden via javascript but already starts to play (autplay-mode) even it's not visible?
我想找到一个简单的方法,通过隐藏视频并在点击预览图像后立即显示,为我的博客中的视频获取自定义预览图像。用户DominicGreen用以下代码帮助我开始使用它。问题是:页面加载后,视频已经开始在自动播放模式下播放(即使它是隐藏的),但我想在点击预览图像后立即开始自动播放。。。
这是我的代码:
<!doctype html>
<script type="text/javascript">
$(window).load(function(){
$(".video").hide();
$(".loader").click(function(){
$(this).hide();
$(this).parent().find(".video").show();
});
});
#container .post .postimg img{
width:100%;
height:auto;
}
#container .post .postvideo{
position:relative;
display:block;
width:100%;
height:430px;
background-color:#0F3;
}
#container .post .postvideo .con{
position:absolute;
top:0;
left:0;
height:100%;
width:100%;
z-index:1;
}
#container .post .postvideo .video{
background-color:#C00;
}
#container .post .postvideo .video iframe{
width:100%;
height:100%;
}
#container .post .postvideo .loader{
background-color:#06C;
}
#container .post .postvideo .loader img{
width:100%;
height:100%;
}
<div class="post">
<div class="postvideo">
<div class="con video">
<iframe width="420" height="315" src="http://www.youtube.com/embed/v_MVwUqrwDc?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>
</div>
<div class="con loader">
<img src="http://cache2.allpostersimages.com/p/LRG/27/2728/9CKND00Z/poster/gulin-darrell-pansy-flowers-floating-in-bird-bath-with-dew-drops-sammamish-washington-usa.jpg" width="758" height="388">
</div>
</div>
</div><!--! end of .post -->
<div class="post">
<div class="postvideo">
<div class="con video">
<iframe src="http://player.vimeo.com/video/29017795?title=0&byline=0&portrait=0&color=a80101&autoplay=1" width="460" height="259" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
</div>
<div class="con loader">
<img src="http://cache2.allpostersimages.com/p/LRG/27/2728/9CKND00Z/poster/gulin-darrell-pansy-flowers-floating-in-bird-bath-with-dew-drops-sammamish-washington-usa.jpg" width="758" height="388">
</div>
</div>
</div><!--! end of .post -->
您将需要使用,
YouTube JavaScript播放器API
或者,
将其作为url(autoplay off
)
http://www.youtube.com/embed/v_MVwUqrwDc?rel=0&autoplay=0"
点击按钮后,将src更改为
http://www.youtube.com/embed/v_MVwUqrwDc?rel=0&autoplay=1"
这不会像js-api那样流畅,但会成功的。
如果您不想使用youtube API或vimeo API,我建议您将iframe src设为空,并在单击加载程序div时设置它。所以
我将使用
<iframe width="420" height="315" src="" frameborder="0" allowfullscreen></iframe>
和
<div class="con loader" data-iframe-src="http://www.youtube.com/embed/v_MVwUqrwDc?rel=0&autoplay=1">
然后在js代码的click事件中,只需将数据iframe-src值设置为iframe-src:
$(this).parent().find(".video iframe").attr("src", $(this).attr("data-iframe-src"));
相关文章:
- 按键时标记为ng的必填字段有效,即使是's是空的
- 使用ajax验证的reCAPTCHA总是返回错误,即使是正确的
- 视频通过javascript被隐藏,但已经开始播放(自动播放模式),即使是's不可见
- 我无法获得热图.js即使是简单的热图也可以工作
- 节点模块导出模式 - 这是正确的吗?
- 在iframe中编辑另一个网页的样式的方法,即使是表面上的
- 页面上的任何按钮都会发送表单,即使是表单标记之外的按钮
- Angularjs模式窗口是动态(编程)构建的
- grunt是如何继续构建的,即使是grunt contrib符号链接也是如此;找不到路
- 在更改时,即使是动态插入的输入标记上的日期选择器的处理程序也不会;不起作用
- chrome setInterval()用于模糊选项卡无法正常工作,即使是1秒或更长时间
- 观察到的变化'添加'回调所有项,即使是数据库中已经存在的项
- 在Javascript中强制使用十进制值,即使是整数
- JavaScript模式:这是为数组分配多个值的有效方法吗?
- Facebook发送对话框问题(我得到一般的错误,即使是最基本的发送链接)
- Javascript在两个函数后失败,即使是相同的函数
- 第一次实现模块模式变量是未定义的
- Jquery ajax总是导致'error'即使是在有效的时候
- 我如何确保我的项目中的所有JSON模式都是有效的
- 未定义的变量,即使是全局定义的