在youtube视频上悬停div

时间:2012-10-19 14:00:00

标签: javascript jquery youtube youtube-api

我有一个脚本正在调用youtube供稿,然后显示视频(没有iframe) 请看一下小提琴:JsFiddle

我想在播放器顶部显示一个img,所以我添加了一个这样的img:

 html += '<span>Top Rated</span><img src="http://christianjamesphoto.com/themes/chrisjames/images/arrow-left.gif" /></div>';

并为其分配z-index:9999;然而,这似乎不起作用。我已经找到了答案,似乎我必须将wmode="transparent"放入链接,但我不知道如何在网址中实现这一点。我该怎么做才能让它在播放器上显示img?

2 个答案:

答案 0 :(得分:2)

您可以在jTubeEmbed插件中添加一个新选项,如下所示:http://jsfiddle.net/aFx29/2/

的变化:

    jTubeEmbed: function(video, options) {
        var options = $.extend({
            // Embed Options
            width: 560,
            height: 340,
            wmode: 'window', // can be window, transparent and opaque

            // Player Options
            autoplay: false,
            fullscreen: false,
            related: true,
            loop: false,
            keyboard: true,
            genie: false,
            border: false,
            highdef: true,
            start: 0
        }, options);

        // ... ommitted for brevity ...

        if(options.wmode) {
            videoEmbed += '<param name="wmode" value="' + options.wmode + '"></param>';
        }

        if(options.fullscreen == true) {
            videoEmbed += '<param name="allowFullScreen" value="true"></param>';
        }

        videoEmbed += '<embed src="'+videoUrl+'"';
        videoEmbed += '    type="application/x-shockwave-flash"';

        if(options.wmode) {
            videoEmbed += '    wmode="' + options.wmode + '"';
        }

        if(options.fullscreen == true) {
            videoEmbed += '    allowfullscreen="true"';
        }

        videoEmbed += '    allowscriptaccess="always"';
        videoEmbed += '    width="'+options.width+'" height="'+options.height+'">';
        videoEmbed += '    </embed>';
        videoEmbed += '</object>';

        return videoEmbed;
    }

并在调用jTubeEmbed时传递您想要的选项,如:

$.jTubeEmbed(this.video, {
    // your options here,
    wmode: 'opaque'
});

答案 1 :(得分:0)

播放器是一个flash对象,要将图像放在顶部,您应该考虑:

Display image above flash object

将此参数添加到videoEmbed:

videoEmbed += '<param name="wmode" value="transparent"></param>';

你可以在你的代码中尝试这样的事情:

html = '<li>';
html += '<div style="position:absolute; top:0px; z-index:2000;"><span>Top Rated</span>';
html += '<img src="http://christianjamesphoto.com/themes/chrisjames/images/arrow-left.gif" alt="" /></div>';
html += $.jTubeEmbed(this.video, embedOptions);
html += '<a href="'+this.link+'">'+this.title+'</a>';
html += '</li>';