jquery – 由于嵌入的视频太多,我的网站加载缓慢

由于嵌入的视频太多,我的网站加载缓慢.我看到有图像的地方(嵌入视频的位置)并点击它,此时加载了嵌入的视频.任何人都可以给我一些帮助,想弄清楚如何做到这一点?也许一旦你将鼠标悬停在图像上,如果加载了youtube嵌入?非常感谢!

解决方法

用户点击图片后,只需使用jQuery插入嵌入代码

只是示例代码HTML

<div id="video" style="background-color:red; width:560px; height:315px;"></div>

jQuery的:

$('#video').on('click',function() {
    $(this).html('<iframe width="560" height="315" src="//www.youtube.com/embed/9bZkp7q19f0?autoplay=1" frameborder="0" allowfullscreen></iframe>').css('background','none');
});

如果你想让视频自动播放,可以像我一样在网址的末尾添加?autoplay = 1.

没有缩略图代码http://jsfiddle.net/KFcRJ/

提取视频缩略图

HTML:

<div id="video" style="background-color:red; width:560px; height:315px;">
<a href="http://www.youtube.com/watch?v=9bZkp7q19f0" class="youtube"></a></div>

jQuery的:

$('#video').on('click',function() {
$(this).html('<iframe width="560" height="315" src="//www.youtube.com/embed/9bZkp7q19f0?autoplay=1" frameborder="0" allowfullscreen></iframe>').css('background','none');
});

function getYoutubeID(url) {
    var id = url.match("[\\?&]v=([^&#]*)");
    id = id[1];
    return id;
};
$('a.youtube').each(function() {
    var id = getYoutubeID( this.href );
    this.id = id;
    var thumb_url = "http://img.youtube.com/vi/"+id+"/maxresdefault.jpg";
    $('<img width="100%" src="'+thumb_url+'" />').appendTo($('#video'));
});

缩略图代码http://jsfiddle.net/89uVe/4/

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...