隐藏时停止 Flash 视频

发布于 2024-10-12 13:04:26 字数 700 浏览 6 评论 0原文

我知道这个问题在 Stack 上已经被问过两次了……但我仍然需要帮助。我有 2 个 div,每个 div 都包含 SWFObject。这是显示/隐藏我的 Div 的 jquery:

$(document).ready(function(){ 
 $("#DIV2").hide();

  $('#button1').bind('click', function() {
    $("#DIV1").hide();
    $("#DIV2").show();
  });

  $('#button2').bind('click', function() {
    $("#DIV1").show();
    $("#DIV2").hide();
});
});

但是我需要 DIV2 中的视频在隐藏时停止播放,并在再次显示时从头开始。根据我的阅读,我需要将其从 DOM 中删除......但我不明白如何重新添加它。我已经看到了 detach(); 的建议但无法弄清楚我的 AppendTo() 会去哪里。

有人可以帮忙吗?我真的很感激。顺便说一句,这里是 相关帖子(其中包含指向另一篇相关帖子的链接)。

先感谢您!

I know this question has been asked twice on Stack....but I still need help. I have 2 divs each containing SWFObjects. Here's the jquery that shows/hides my Divs:

$(document).ready(function(){ 
 $("#DIV2").hide();

  $('#button1').bind('click', function() {
    $("#DIV1").hide();
    $("#DIV2").show();
  });

  $('#button2').bind('click', function() {
    $("#DIV1").show();
    $("#DIV2").hide();
});
});

But I need my video in DIV2 to STOP PLAYING when it's hidden, and start from the beginning when you show it again. From what I read, I need to remove it from the DOM...but I don't understand how to re-add it. I've seen suggestions for detach(); but can't figure out where my AppendTo() would go.

Can anyone help?? I'd really appreciate it. BTW, here is a related post (which contains a link to ANOTHER related post).

Thank you in advance!

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

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

发布评论

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

评论(2

和我恋爱吧 2024-10-19 13:04:26

谢谢你的帮助,本。在看到您最近的回复之前,我最终使用了我在 类似的帖子,但像这样调整:

 // Remove and re-add video
 var clone = $("#video").clone(true);
 $("#video").remove();
 $("#video-holder").html(clone);

这对我来说非常有效。我给了我的 swfobject 一个 ID“video”,它位于 div“video-holder”内。希望这对其他人有帮助!

Thanks for your help Ben. Before I saw your most recent response, I ended up using what I had seen in an answer to a similar post but adjusted it like so:

 // Remove and re-add video
 var clone = $("#video").clone(true);
 $("#video").remove();
 $("#video-holder").html(clone);

This worked perfectly for me. I gave my swfobject an ID "video", which sat within the div "video-holder". Hope this helps others!

左岸枫 2024-10-19 13:04:26

根据我之前的经验,分离包含 flash 对象的 DOM 元素很容易导致浏览器崩溃,如果我没记错的话,firefox 特别容易受到攻击。

您可以通过执行类似 $("#DIV1 OBJECT").remove() 之类的操作来删除子元素,然后在再次需要它们时使用 swfobject 再次添加。

或者,您可以使用 ExternalInterface 尝试通过 JavaScript 与 Flash 对象进行通信。

您并没有说明如何播放视频,但是如果您有自己的自定义播放器,则需要在 Flash 文件中添加一些接口才能做到这一点,否则,您使用的播放器可能有一些现有的外部接口你可以用它。

From my previous experience, detaching DOM elements that contain flash object is very prone to crashing the browser, firefox was particularly vulnerable if i remember correctly.

You could remove the sub elements by doing something like $("#DIV1 OBJECT").remove() and add then again with swfobject when you need them again.

Or, you could use ExternalInterface to try to communicate with your flash objects from javascript.

You're not saying how you play the videos, but if you have your own custom player, you'll need to add some interfaces to your flash file to do that, otherwise, the player you're using might have some existing external interfaces you can use for that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文