preload image with javascript and display when ready

前端 未结 2 836
谎友^
谎友^ 2020-12-20 08:45

I want to show a low-res image and start loading the hi-res image after the complete page has rendered. Only when the hi-res image is completely loaded, I want to replace th

2条回答
  •  甜味超标
    2020-12-20 09:35

    Use this script to preload the images:

    
    

    Then use low-res images in your html as you need and change to hi-res images when needed. The preloaded image is there for you.

    $(window).load(function(){
       $(selector).css('background-image',images[0]);
    });
    

提交回复
热议问题