动态创建 Fancybox 并将视频粘贴到其中

发布于 2024-09-07 20:32:58 字数 94 浏览 5 评论 0原文

我需要将页面上的所有 HTML5 视频标签替换为附加了点击事件的海报图像;单击事件会启动包含该视频标签的 Fancybox。有人知道如何用 jQuery 做到这一点吗?谢谢。

I need to replace all the HTML5 video tags on the page with their poster image that has a click event attached; the click event launches a Fancybox containing that video tag. Anyone know how to do this with jQuery? Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

忆沫 2024-09-14 20:32:58

我发现过去将 fancyBox 与对话视频结合使用的最佳方法是为您的 FLV 播放器创建一个空的 Flash 视频容器 div。然后,在加载 fancyBox 对话框时,您可以使用 fancyBox 上的“onStart”事件来定位容器 div,并用视频播放器内容填充它。然后,这会触发视频在您已经通过 fancyBox 显示的 div 容器中渲染。最后一部分是获取 fancyBox 正确的视频加载后尺寸,这取决于您的 FLV 播放器是否有要连接的事件以及 FLV 播放器是否能够为您提供电影尺寸。

有关此方法的完整教程,请参阅以下网址:

集成的 flowPlayer、fancyBox 和轮播教程。

有关实际演示,请参阅:

集成演示

I've found that in the past the best way to use fancyBox with dialog videos is to create an empty flash video container div for your FLV player. Then on loading your fancyBox dialog you use the on fancyBox 'onStart' event to target the container div, populate it with the video player content. This then triggers the video to render in the div container you are already showing via fancyBox. The last part is getting the dimensions of the fancyBox correct post video load, this depends on your FLV player having an event to hook on to and the FLV player being able to provide you with the movie dimensions.

For a full tutorial on this approach see the following url:

integrated flowPlayer, fancyBox and carousel tutorial.

And for a demonstration of this in action see:

integration demonstration

客…行舟 2024-09-14 20:32:58

也许更好的方法是使用一系列包含海报 img 的 div,然后将 onclick 事件附加到海报,以在框中呈现视频标签(或更改视频标签的源)。

Mobile Safari 允许点击事件触发视频播放,因此这也应该适用于 iPad。这也意味着用户无需单击海报图像两次即可播放视频(因为移动 Safari 不支持单击事件)。

Maybe a better way would be to have a series of divs containing the poster img then attach an onclick event to the poster that renders the video tag (or changes the source of the video tag) in the box.

Mobile Safari allows click events to trigger a video to play so this should also work on the iPad. This also means users won't be required to click the poster image twice to play the video (since mobile Safari does not support the click event).

屋檐 2024-09-14 20:32:58

找到了解决办法,调用$(window).load函数;该问题是为了解决 Safari 5/iPad 上的问题。我知道我们不应该使用特定于浏览器的东西,但这是解决这个特定问题的唯一方法:)

$(window).load(function () {
 if (jQuery.browser.safari) {
   var videoTag = "";
   var posterPath = "";
   var replacement = "";
   var boxId = "";
   var el = "";
   $("[id^='vid-']").each(function(){
     videoTag = "";
     posterPath = "";
     replacement = "";
     boxId = "";
     el = "";

     el = $('[id='+this.id+']');
     videoTag = el.parent().html();
     posterPath = el.parent().find("img").attr("src");
     boxId = this.id + "_manual";
     replacement = "<a title='' id='" + boxId + "' href='javascript:;'><img src='" +
       posterPath + "' style='float:left; padding-left:5px; '/></a>"
     el.parent().replaceWith(replacement);

     $("[id="+boxId+"]").fancybox( 
         {
           'content'   : videoTag,
           'autoDimensions' :true,
           'padding'   : 9,
           'showCloseButton' : true,
           'enableEscapeButton': true       
         }
     ); // end click function
   }); // end each function
 }  // end if
}  // end load function

Found a solution, called on the $(window).load function; the issue is to address a problem on Safari 5/iPad. I know we're not supposed to use browser-specific stuff, but this is the only way to solve this particular issue :)

$(window).load(function () {
 if (jQuery.browser.safari) {
   var videoTag = "";
   var posterPath = "";
   var replacement = "";
   var boxId = "";
   var el = "";
   $("[id^='vid-']").each(function(){
     videoTag = "";
     posterPath = "";
     replacement = "";
     boxId = "";
     el = "";

     el = $('[id='+this.id+']');
     videoTag = el.parent().html();
     posterPath = el.parent().find("img").attr("src");
     boxId = this.id + "_manual";
     replacement = "<a title='' id='" + boxId + "' href='javascript:;'><img src='" +
       posterPath + "' style='float:left; padding-left:5px; '/></a>"
     el.parent().replaceWith(replacement);

     $("[id="+boxId+"]").fancybox( 
         {
           'content'   : videoTag,
           'autoDimensions' :true,
           'padding'   : 9,
           'showCloseButton' : true,
           'enableEscapeButton': true       
         }
     ); // end click function
   }); // end each function
 }  // end if
}  // end load function
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文