How to create a JavaScript callback for knowing when an image is loaded?

前端 未结 10 1105
太阳男子
太阳男子 2020-11-22 04:56

I want to know when an image has finished loading. Is there a way to do it with a callback?

If not, is there a way to do it at all?

10条回答
  •  终归单人心
    2020-11-22 05:43

    these functions will solve the problem, you need to implement the DrawThumbnails function and have a global variable to store the images. I love to get this to work with a class object that has the ThumbnailImageArray as a member variable, but am struggling!

    called as in addThumbnailImages(10);

    var ThumbnailImageArray = [];
    
    function addThumbnailImages(MaxNumberOfImages)
    {
        var imgs = [];
    
        for (var i=1; i0) 
                    {
                        if(c != i)
                            images[c] = images[i];
                        c++;
                    }
                }
    
                images.length = c;
    
                DrawThumbnails();
            });
    }
    
    
    
    function preloadimages(arr)
    {
        var loadedimages=0
        var postaction=function(){}
        var arr=(typeof arr!="object")? [arr] : arr
    
        function imageloadpost()
        {
            loadedimages++;
            if (loadedimages==arr.length)
            {
                postaction(ThumbnailImageArray); //call postaction and pass in newimages array as parameter
            }
        };
    
        for (var i=0; i

提交回复
热议问题