Reload multiple images using Jquery? How to optimize?

0

I have an update of multiple images using Jquery:

window.onload = function() {
    setInterval(function(){

        $( ".image" ).each(function( index ) {

            base_url = $(this).attr('src').split('?rand=')[0];
            address = base_url + '?rand=' + Math.random();
            $(this).attr("src", address);

        });

    },10000);

}; 

I'm trying to optimize it:

function update(){
    setInterval(function() {
        $(".cameragrid_").find("img").each(function(index) {
            d = new Date();
            var src = $(this)[0].src;
            var state = $(this).context.readyState;
            if(state == 'complete');{
                $(this).attr("src",src+d.getTime());
            }
        });
        console.log('click');
    }, 10000);
}


    $(window).ready(function(){
        $('.cameragrid_').hide();
    });

    $(window).load(function (){
        $('.cameragrid_').show();
        update();
    }
);

I wanted to decrease the time from 10 to 3 seconds, but when I decrease this time, I do not update all the images, my algorithm stops and the rest is not updated. .

Is there any way to optimize it so that it runs within 3 seconds?

    
asked by anonymous 23.03.2016 / 19:42

1 answer

1

I ended this way:

setInterval(function(){

                $( ".image" ).each(function( index ) {

                    var img = new Image();
                    img.src = $(this).attr('src');

                    console.log(img.complete);

                    if(img.complete){

                    console.log($(this).attr('src') + ' - done!');

                    base_url = $(this).attr('src').split('?rand=')[0];
                    address = base_url + '?rand=' + Math.random();
                    $(this).attr("src", address);

                    }

                });

            },500);
    
15.04.2016 / 18:09