播放图标youtube视频div叠加

时间:2012-06-19 10:04:24

标签: javascript jquery youtube overlay

我有图片导航,但客户希望通过产品说明添加视频图标。

enter image description here

当用户点击视频图标时,它应该将YouTube视频叠加在主产品图片的顶部。有点像隐藏它,只是显示视频。

我找不到任何可以执行此操作的jquery插件?

这是我创建的一些示例标记,当您单击图标上的播放时,我希望在图像顶部的红色框内播放YouTube视频。

查看我的示例: http://jsfiddle.net/mC5c3/4/

HTML:

<div class="container">

<div class="product-image">
<img src="http://www.skriftlig.com/konfliktmegling/wp-content/uploads/2010/02/Photoxpress_2658886-480x220.jpg" alt="http://www.skriftlig.com/konfliktmegling/wp-content/uploads/2010/02/Photoxpress_2658886-480x220.jpg">
</div>

    <div class="image-nav">
    </div>

    <div class="icon">
        &nbsp
    </div>

</div>

CSS:

div.container
{
    margin:10px 10px auto;
    border:1px solid orange;
}

div.product-image
{
    height:220px;
    width:480px;
    border:1px solid red;  
    margin:30px;        
}

div.image-nav
{
    border:1px solid black;
    width:500px;
    height:100px;
    margin:30px;
}

div.icon
{
background-image: url("http://i.stack.imgur.com/zsQik.png");
    background-repeat: no-repeat;
    height: 50px;
    left: 540px;
    position: relative;
    top: -104px;
    width: 50px;
}

修改

  1. 应该基于图标点击。
  2. 并根据图标的点击显示和隐藏。
  3. 视频需要嵌入图标div中,以便客户端可以更改视频。
  4. 我添加了点击事件并调整了视频大小

    var $video=$('<iframe width="480" height="220" src="http://www.youtube-nocookie.com/embed/jvTv_oatLA0?rel=0" frameborder="0" allowfullscreen></iframe>');
    var $productImage=$('.product-image');
    var $icon=$('.icon');
    $icon.on('click',function()
    {
        $('.product-image').append($video);
    });
    

2 个答案:

答案 0 :(得分:1)

var $icon=$('.icon');
var $video=$('.product-image iframe');
$icon.on('click',function()
{
    $video.toggle();//Shows the video if hidden, hides the video if visible.
});

答案 1 :(得分:0)

您可以使用tube api执行此操作:

function play() {
  if (ytplayer) {
    ytplayer.playVideo();
  }
}

Read you tube API参考:https://developers.google.com/youtube/js_api_reference?hl=fr-FR#onYouTubePlayerReady

相关问题