想在网页后期加载图片,简单,如下例子:
var delayPics=$('.delayPics');
var _picNum = delayPics.length;
if(_picNum > 0){
//!--_picNum
//delayPics.each(function(index,item){
$.each(delayPics,function(index,item){
//$(item).attr("clickable")
//$(this).trigger("hover",window.event);
let picid=$(this).data("id");
$.ajax({
type: "GET",
url: "gopic_subject.php?id="+picid,
beforeSend: function (xhr) {
xhr.overrideMimeType('text/plain; charset=x-user-defined');
},
success: function (result, textStatus, jqXHR) {
if(result.length < 1){
alert("The thumbnail doesn't exist");
$(item).attr("src", "data:image/png;base64,");
return
}
var binary = "";
var responseText = jqXHR.responseText;
var responseTextLen = responseText.length;
for ( i = 0; i < responseTextLen; i++ ) {
binary += String.fromCharCode(responseText.charCodeAt(i) & 255)
}
$(item).attr("src", "data:image/png;base64,"+btoa(binary));
},
error: function(xhr, textStatus, errorThrown){
alert("Error in getting document "+textStatus);
}
});
});
}