嗨,我有这个javascript代码:
$.fn.imagesLoaded = function () {
$imgs = this.find('img[src!=""]');
if (!$imgs.length) {return $.Deferred.resolve().promise();}
var dfds = [];
$imgs.each(function(){
var dfd = $.Deferred();
dfds.push(dfd);
var img = new Image();
img.onload = function(){dfd.resolve();}
img.src = this.src;
});
return $.when.apply($,dfds);
}
var disc = function(div,of){
$(div).hide();
$('#loading').show();
var ajax = $.ajax({url : of, type : "GET", cache: false});
ajax
.done(function(response){
Commons.sorDone(div, response);
FB.XFBML.parse(document.getElementById('.fb-comments'));
twttr.widgets.load();
})
.fail(function(){
Commons.sorFail(div);
});
}
Commons = {
sorDone : function (div, response) {
$(div).html(response).imagesLoaded().then(function(){
$('#loading').hide();
$(div).show();
});
},
}代码是通过div中的一个按钮动态加载内容。在充电时,内容显示为gif预加载。
好吧,那些内容不是社交按钮facebook和twitter,facebook的评论框也显示,为了被FB.XFBML.parse解析
到目前为止还不错,但问题是,有时会出现facebook评论,有时则没有显示空空间和评论。
哪里可能是错的?
发布于 2015-08-16 14:52:46
我已经解决了当放置在下面显示的div在末尾。
因为如果有人帮忙的话。不再失败,它将始终发现解析。
$.fn.imagesLoaded = function () {
$imgs = this.find('img[src!=""]');
if (!$imgs.length) {return $.Deferred.resolve().promise();}
var dfds = [];
$imgs.each(function(){
var dfd = $.Deferred();
dfds.push(dfd);
var img = new Image();
img.onload = function(){dfd.resolve();}
img.src = this.src;
});
return $.when.apply($,dfds);
}
var disc = function(div,of){
$(div).hide();
$('#loading').show();
var ajax = $.ajax({url : of, type : "GET", cache: false});
ajax
.done(function(response){
Commons.sorDone(div, response);
})
.fail(function(){
Commons.sorFail(div);
});
}
Commons = {
sorDone : function (div, response) {
$(div).html(response).imagesLoaded().then(function(){
$('#loading').hide();
$(div).show();
FB.XFBML.parse(document.getElementById('.fb-comments'));
twttr.widgets.load();
});
},
}https://stackoverflow.com/questions/32009113
复制相似问题