我创建了一个包含多种媒体的页面,每个媒体都在一个隐藏的 div 中,当单击菜单链接时,该隐藏的 div 被触发以加载到 jquery 工具中覆盖。单击链接时我希望实现的几件事:
- 视频加载到叠加层时自动播放
- 覆盖关闭时视频暂停或停止
- 如果再次单击同一链接,视频会重新加载并自动播放
我达到了 #2,但在 #1 和 #3 上失败了。使用下面的代码,视频播放器和媒体在覆盖中加载但不会自动播放,并且当尝试关闭链接并重新打开时播放器无法加载。
我在下面的代码中做错了什么?
<div id="menu">
<a href="#"><img src="images/image1.jpg" rel="#overlay1"/></a>
<a href="#"><img src="images/image2.jpg" rel="#overlay2"/></a>
<a href="#"><img src="images/image3.jpg" rel="#overlay3"/></a>
</div>
<div class="overlay" id="overlay1">
<video class="player" id="bbb" controls="controls" poster="http://sandbox.thewikies.com/vfe-generator/images/big-buck-bunny_poster.jpg" width="640" height="360">
<source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" type="video/mp4" />
<source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.webm" type="video/webm" />
<source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.ogv" type="video/ogg" />
<object type="application/x-shockwave-flash" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="640" height="360">
<param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" />
<param name="allowFullScreen" value="true" />
<param name="wmode" value="transparent" />
<param name="flashVars" value="config={'playlist':['http%3A%2F%2Fsandbox.thewikies.com%2Fvfe-generator%2Fimages%2Fbig-buck-bunny_poster.jpg',{'url':'http%3A%2F%2Fclips.vorwaerts-gmbh.de%2Fbig_buck_bunny.mp4','autoPlay':true}]}" />
<img alt="Big Buck Bunny" src="http://sandbox.thewikies.com/vfe-generator/images/big-buck-bunny_poster.jpg" width="640" height="360" title="No video playback capabilities, please download the video below" />
</object>
</video>
</div>
<div class="overlay" id="overlay2">(same as above, different media)</div>
<div class="overlay" id="overlay2">(same as above, different media)</div>
<script>
$(function() {
$("a [rel]").overlay({
effect: 'apple',
expose: '#101010',
closeOnClick: 'false',
closeOnEsc: 'false',
onLoad: function(content) {
this.getOverlay().find(".player").flowplayer(0).load();
$('#bbb').get(0).play()
},
onClose: function(content) {
$(".overlay").children().filter("video").each(function(){
this.pause();
});
}
});
$(".player").flowplayer("http://releases.flowplayer.org/swf/flowplayer-3.2.11.swf", {clip: {autoPlay: true}});
});
</script>