【问题标题】:Video is not playing on its image placeholder with jquery视频未使用 jquery 在其图像占位符上播放
【发布时间】:2012-11-20 21:23:47
【问题描述】:

我想在点击占位符(图片)时播放视频。这是代码。

html

 <div class="ytembed">
        <a href="http://player.vimeo.com/video/27243869?title=1&byline=1&portrait=1">
            <img width="560" height="315" src="http://placehold.it/560x315" alt="Click to play"/>
        </a>
    </div>​

jquery

$(function() {
    $('.ytembed:not(.processed)').addClass('processed').each(function() {
        $(this).find('a').click(function(e) {
            e.preventDefault();
            var width = $(this).find('img').width();
            var height = $(this).find('img').height();
            var url = $(this).attr('href');
            var $iframe = $('<iframe src="' + url + '" width="' + width + '" height="' + height + '" frameborder="0"/>');
            $(this).parent().html($iframe);
        });
    });
});​

请告诉我该怎么做。这是jsfiddle版本http://jsfiddle.net/fEzLZ/

提前致谢。

【问题讨论】:

  • 您的意思是要加载视频然后自动播放吗?因为视频加载对我来说很好。
  • 是的,但我想在单击图像缩略图时播放它。谢谢...

标签: jquery youtube


【解决方案1】:

尝试将“autoplay=1”添加到您的 Vimeo 网址的末尾。生成的 URL 应该是

"http://player.vimeo.com/video/27243869?title=1&byline=1&portrait=1&autoplay=1"

【讨论】:

  • 谢谢,我很感激。但是有可能从jquery实现它吗?我的意思是客户可能不知道。所以我愿意用jquery来做。无论是 youtube 还是 vimeo 视频。
  • 您好,自动播放功能适用于 vimeo 视频,但使用 &amp;autoplay=1 无法播放 youtube 视频。这是 jsfiddle jsfiddle.net/fPDwu/2
  • 您的 YouTube 嵌入网址格式不正确。这是一个有效的小提琴:jsfiddle.net/3Hw3W
  • 很抱歉再次打扰,我刚刚注意到“jsfiddle.net/fPDwu”在 ipad 上不起作用,但在所有浏览器上的 PC 上都能正常工作。有什么建议吗?
  • 您嵌入的视频是否允许显示为 HTML5 而不是 Flash?如果它不能在 iPad 上运行,我的猜测是不会,因为 iPad 不支持 Flash。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-15
  • 1970-01-01
  • 2017-02-10
  • 1970-01-01
相关资源
最近更新 更多