问题描述
因此背景是:检查youtube缩略图的大小,然后根据该大小
$(".video-container").each( function() {
var iframe = $(this).children('iframe');
var iframe_src = iframe.attr('src');
var youtube_video_id = iframe_src.match(/youtube\.com.*(\?v=|\/embed\/)(.{11})/).pop();
$(this).css( "background-image","url('https://img.youtube.com/vi/"+youtube_video_id+"/maxresdefault.jpg')" );
// Put in thumbnail for checking
$(this).prepend( "<img src='https://img.youtube.com/vi/"+youtube_video_id+"/maxresdefault.jpg' class='test-embed-thumb'>" );
// load and check video thumb size - this is the part make the result different everytime,is there other function I can use
$(".test-embed-thumb").load( "src",function(){
var image_width = $(this).width();
alert(image_width);
if (image_width <= 120){
$(this).parent().css( "background-image","url('https://img.youtube.com/vi/"+youtube_video_id+"/hqdefault.jpg')");
$('.test-embed-thumb').hide();
}else {
$('.test-embed-thumb').hide();
}
});
});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)