【【预加载图片显示重复有关问题,已赋多张截图和源码】】-【求大神解答】
【【预加载图片显示重复问题,已赋多张截图和源码】】---【求大神解答】
http://imgsrc.baidu.com/forum/w%3D580/sign=bfe4d94b8f5494ee87220f111df4e0e1/7f1d8826cffc1e17c6b8d4c54990f603728de977.jpg
http://imgsrc.baidu.com/forum/w%3D580/sign=bfe4d94b8f5494ee87220f111df4e0e1/7f1d8826cffc1e17c6b8d4c54990f603728de977.jpg
http://imgsrc.baidu.com/forum/w%3D580/sign=f9b5e19097eef01f4d1418cdd0ff99e0/be92c5fc1e178a82f43b2754f503738da877e877.jpg
源码如下
//创建图片元素
function loadImg(ImgList,FileName) {
for (var i = 0; i < ImgList.length; i++) {
if (ImgList[i] != null && ImgList[i] != "" && ImgList[i] != undefined) {
var imgsrc = "/" + window.domainlink + "/UploadFile/" + FileName + "/" + ImgList[i];
var img = new Image();
img.src = imgsrc;
if (img.complete == true) Imgcall(img);
else img.onload = function () { Imgcall.call(img) };
}
}
}
//图片预加载回调方法
function Imgcall() {
var imgsrc = this.src;
var width = this.width;
var height = this.height;
var img = document.createElement("img");
img.src = imgsrc;
img.setAttribute("class", "MycoImgload");
if (width != height && width > 0 && height > 0) {
if (width > height) {
height = 100 * height / width;
width = 100;
img.style.marginTop = (100 - height) / 2 + "px";
}
else {
width = 100 * width / height;
height = 100;
}
img.style.width = width + "px";
img.style.height = height + "px";
}
else {
img.style.width = "100px";
img.style.height = "100px";
}
var div = document.createElement("div");
div.setAttribute("class", "divimg")
div.appendChild(img);
dropbox.appendChild(div);
GetImgNameList($("#dropbox .divimg"));
}
------解决思路----------------------
(function(img){
if (img.complete == true) Imgcall(img);
else img.onload = function () { Imgcall.call(img) };
})(img);
这样试下
http://imgsrc.baidu.com/forum/w%3D580/sign=bfe4d94b8f5494ee87220f111df4e0e1/7f1d8826cffc1e17c6b8d4c54990f603728de977.jpg
http://imgsrc.baidu.com/forum/w%3D580/sign=bfe4d94b8f5494ee87220f111df4e0e1/7f1d8826cffc1e17c6b8d4c54990f603728de977.jpg
http://imgsrc.baidu.com/forum/w%3D580/sign=f9b5e19097eef01f4d1418cdd0ff99e0/be92c5fc1e178a82f43b2754f503738da877e877.jpg
源码如下
//创建图片元素
function loadImg(ImgList,FileName) {
for (var i = 0; i < ImgList.length; i++) {
if (ImgList[i] != null && ImgList[i] != "" && ImgList[i] != undefined) {
var imgsrc = "/" + window.domainlink + "/UploadFile/" + FileName + "/" + ImgList[i];
var img = new Image();
img.src = imgsrc;
if (img.complete == true) Imgcall(img);
else img.onload = function () { Imgcall.call(img) };
}
}
}
//图片预加载回调方法
function Imgcall() {
var imgsrc = this.src;
var width = this.width;
var height = this.height;
var img = document.createElement("img");
img.src = imgsrc;
img.setAttribute("class", "MycoImgload");
if (width != height && width > 0 && height > 0) {
if (width > height) {
height = 100 * height / width;
width = 100;
img.style.marginTop = (100 - height) / 2 + "px";
}
else {
width = 100 * width / height;
height = 100;
}
img.style.width = width + "px";
img.style.height = height + "px";
}
else {
img.style.width = "100px";
img.style.height = "100px";
}
var div = document.createElement("div");
div.setAttribute("class", "divimg")
div.appendChild(img);
dropbox.appendChild(div);
GetImgNameList($("#dropbox .divimg"));
}
------解决思路----------------------
(function(img){
if (img.complete == true) Imgcall(img);
else img.onload = function () { Imgcall.call(img) };
})(img);
这样试下