Javascript 加载时图像为黑色(涉及jquery Jack Moore的图像缩放插件)

Javascript 加载时图像为黑色(涉及jquery Jack Moore的图像缩放插件),javascript,html,jquery,css,jquery-plugins,Javascript,Html,Jquery,Css,Jquery Plugins,我有一个动态添加的图像,但加载时它是黑色的(我知道它已加载,因为我尝试放置加载的gif,并将其设置为在加载图像时将其删除,但gif没有显示)。我退出我创建的窗口(只是一个大的div块),然后再次进入,图像显示正常 我基本上创建了一个名为appendImg()的函数来动态添加图像,如下所示,这些图像都使用了我安装的Jack Moore的jquery zoom插件。这个插件基本上允许我在点击图像时放大它,所以它需要我为插件创建一个id,然后将图像附加到id中 如何在不关闭和打开div的情况下使图像正

我有一个动态添加的图像,但加载时它是黑色的(我知道它已加载,因为我尝试放置加载的gif,并将其设置为在加载图像时将其删除,但gif没有显示)。我退出我创建的窗口(只是一个大的div块),然后再次进入,图像显示正常

我基本上创建了一个名为appendImg()的函数来动态添加图像,如下所示,这些图像都使用了我安装的Jack Moore的jquery zoom插件。这个插件基本上允许我在点击图像时放大它,所以它需要我为插件创建一个id,然后将图像附加到id中

如何在不关闭和打开div的情况下使图像正常显示?现在我仍然在桌面上编写代码,但我稍后会使用Github发布网站,这会使图像加载更快吗?谢谢

我试着在没有像这样使用插件的情况下正常添加一个图像,它会立即显示出来,所以这一定是因为插件没有让图像立即显示出来:

function appendNormalImg(imgName){
    var image = document.createElement("img");                  
    image.src = imgName;
    image.alt = "image";
    image.setAttribute("class", "normalImage");            

    $(".infoContent").append(image);                   
}

没有提供足够的细节来回答这个问题。有很多原因,它看起来就是这样。你使用懒散的图像吗?@RubixOverflowNo@StackSlave我的问题补充了更多细节,你介意看一下吗?谢谢。例子很清楚。跟着他们。
function appendImg(imgName){
    zoomNum+=1;   //variable is initialized at top of the javascript file
    var zoomNumString = zoomNum.toString();          //create id name for new zoom class
    var zoomID = "zoomId" + zoomNumString;

    var newZoomClass = document.createElement("div");         //create new zoom class for each image
    newZoomClass.setAttribute("class", "zoom");
    newZoomClass.setAttribute("id", zoomID);            //new ID for zoom container (since I may use this function multiple times to add multiple images)

    $(".infoContent").append(newZoomClass);

    var image = document.createElement("img");                  //create img element
    image.src = imgName;
    image.alt = "image";
    var imgID = "imgID" + zoomNumString;
    image.setAttribute("id", imgID);            //new ID for image to get width below (again, because I want multiple images)

    zoomID = "#"+zoomID;
    imgID = "#"+imgID;

    $(zoomID).append(image);                   //appendchild image to specific zoom ID

    var imgHeight = $(imgID).height();
    $(zoomID).height(imgHeight);

    var imgWidth = $(imgID).width();
    $(zoomID).width(imgWidth);

    $(document).ready(function(){                                //jquery plugin zoom function for zooming in on picture
        $(zoomID).zoom({on:'click', magnify:1,url:false, touch:true});
    });

    $(imgID).ready(function(){                                    
        $("#loader").remove();
    });
}