Is it possible to reload a specific image if it did not finish loading after a preset amount of time? javascript/jquery

前端 未结 2 1011
抹茶落季
抹茶落季 2020-12-21 02:59

I am running a online photography portfolio and sometimes, 1 or 2 images on a page fails to load. and refreshing will display the failed to load image.

Scenario: I c

2条回答
  •  有刺的猬
    2020-12-21 03:10

    @Pointy and @Gaby are right in their comments. Still I was curious about how to accomplish this.

    This is what I came up with for what it's worth. Untested, though.

    var images = $('img');  // Get all images. (you'll want to modify the selector
                            //    to work with only the desired images)
    
    images.load(function() {       // Add a load event hander that removes 
        images = images.not(this); //    each image from images once loaded.
    });
    
    setTimeout(function(){        // After 10 seconds, iterate over each remaining
        images.each(function() {  //     image, reloading each one
            // reload this image
        });
    },10000);  // run after 10 seconds
    

提交回复
热议问题