jquery 选项卡内容与显示/隐藏 YouTube 视频

发布于 2024-12-03 04:46:30 字数 2052 浏览 2 评论 0原文

我有一个视频部分,设置如下:

页面加载时默认显示一个视频

有两个内容选项卡 - 每个选项卡包含一个视频缩略图列表。当您单击其中一个缩略图时,默认视频会消失,而单击的视频会显示在其位置。

我正在使用在这里找到的一些代码: Flash 视频仍在使用 jQuery 删除的 DIV 上播放(IE 错误) - 删除视频并克隆它,因为我遇到了问题IE 中,即使正在加载新视频,上一个视频仍在播放。

现在在 IE9 中,视频的第一个选项卡列将不会被替换。然而,第二个选项卡列将会。

这是 HTML:

<div class="video-holder">

  <div id="video17" class="large-video" style="display: none;">
   <div class="embed-video">the video</div>
  </div>

  <div id="video18" class="large-video" style="display: none;">
   <div class="embed-video">the video</div>
  </div>

  <div id="video19" class="large-video" style="display: none;">
   <div class="embed-video">the video</div>
  </div>

  <div id="video20" class="large-video" style="display: none;">
   <div class="embed-video">the video</div>
  </div>

</div>

<ul>
<li><a href="#video-tab1">Tab 1</a></li>
<li><a href="#video-tab2">Tab 2</a></li>
</ul>

<div id="video-tab1">
    <a href="#" id="link17" class="video-link">thumbnail</a>
    <a href="#" id="link18" class="video-link">thumbnail</a>
</div>

<div id="video-tab2">
    <a href="#" id="link19" class="video-link">thumbnail</a>
    <a href="#" id="link20" class="video-link">thumbnail</a>
</div>

这是 JS:

jQuery(".large-video").hide(); //hides all the .large-video divs
jQuery("#video17").show(); // this is the default video to show

jQuery(".video-link").click(function(e){
e.preventDefault();
$(".large-video").hide()
$("#video"+$(this).attr("id").replace("link","")).show();    
 var clone = $(".large-video").clone(true);
$(".large-video").remove();
$(".video-holder").html(clone);
});

感谢您提供的任何帮助!

I have a video section that is setup as follows:

One video shows up by default when the page loads

There are two tabs of content - each tab holds a list of video thumbnails. When you click on one of the thumbnails, the default video disappears and the video that was clicked shows up in it's place.

I'm using a bit of code I found here: Flash video still playing on DIV that is removed using jQuery (IE bug) - to remove the video and clone it because I was having an issue in IE where the previous video was still playing even though the new video was being loaded.

Now in IE9, the first tab column of videos will not swap out. The second tab column however will.

This is the HTML:

<div class="video-holder">

  <div id="video17" class="large-video" style="display: none;">
   <div class="embed-video">the video</div>
  </div>

  <div id="video18" class="large-video" style="display: none;">
   <div class="embed-video">the video</div>
  </div>

  <div id="video19" class="large-video" style="display: none;">
   <div class="embed-video">the video</div>
  </div>

  <div id="video20" class="large-video" style="display: none;">
   <div class="embed-video">the video</div>
  </div>

</div>

<ul>
<li><a href="#video-tab1">Tab 1</a></li>
<li><a href="#video-tab2">Tab 2</a></li>
</ul>

<div id="video-tab1">
    <a href="#" id="link17" class="video-link">thumbnail</a>
    <a href="#" id="link18" class="video-link">thumbnail</a>
</div>

<div id="video-tab2">
    <a href="#" id="link19" class="video-link">thumbnail</a>
    <a href="#" id="link20" class="video-link">thumbnail</a>
</div>

And here is the JS:

jQuery(".large-video").hide(); //hides all the .large-video divs
jQuery("#video17").show(); // this is the default video to show

jQuery(".video-link").click(function(e){
e.preventDefault();
$(".large-video").hide()
$("#video"+$(this).attr("id").replace("link","")).show();    
 var clone = $(".large-video").clone(true);
$(".large-video").remove();
$(".video-holder").html(clone);
});

Thank you for any help you can provide!!!

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

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

发布评论

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

评论(1

回首观望 2024-12-10 04:46:30

这就是我要做的:

$(document).ready( function() {
$(".large-video").hide(); //hides all the .large-video divs
$("#video17").show(); // this is the default video to show
$(".video-link").click(function(){
$(".large-video").hide();
$("#video"+$(this).attr("id")).show();    
});
});

然后你的链接应该是:

<div id="video-tab1">
    <a href="#" id="17" class="video-link">thumbnail</a>
    <a href="#" id="18" class="video-link">thumbnail</a>
</div>

<div id="video-tab2">
    <a href="#" id="19" class="video-link">thumbnail</a>
    <a href="#" id="20" class="video-link">thumbnail</a>
</div>

所以基本上它所做的就是等待文档准备好,然后隐藏所有视频 div 并显示默认 div (#video17)。然后,当您单击链接时,它会添加“#video”部分,然后添加 id 标记,并显示生成的 div。因此 ID 为“19”的链接将变为“#video19”。我不确定所有 .remove 和克隆内容的用途是什么,所以我跳过了它。

希望这会有所帮助,或者至少让您朝着正确的方向前进。

Here's what I would do:

$(document).ready( function() {
$(".large-video").hide(); //hides all the .large-video divs
$("#video17").show(); // this is the default video to show
$(".video-link").click(function(){
$(".large-video").hide();
$("#video"+$(this).attr("id")).show();    
});
});

and then your links should be:

<div id="video-tab1">
    <a href="#" id="17" class="video-link">thumbnail</a>
    <a href="#" id="18" class="video-link">thumbnail</a>
</div>

<div id="video-tab2">
    <a href="#" id="19" class="video-link">thumbnail</a>
    <a href="#" id="20" class="video-link">thumbnail</a>
</div>

So that basically what it's doing is it waits until the document is ready, then it hides all your video divs and shows your default div (#video17). Then, when you click on a link, it adds the "#video" part already, then it adds the id tag to that, and shows the resulting div. So a link with the id "19" becomes "#video19". I wasn't sure what all the .remove and clone stuff was for, so I skipped it.

Hope this helps, or at least gets you headed in the right direction.

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