Delay image loading with jQuery

后端 未结 4 1169
攒了一身酷
攒了一身酷 2020-12-04 14:36

I have a page with several galleries including accordions and sliders. The problem is that the page takes forever to load. Is there a way of wrapping an image in a bit of

4条回答
  •  爱一瞬间的悲伤
    2020-12-04 15:15

    Sure you can. Replace your img src attributes with a "#", and add a custom attribute, something like this:

    
    

    Then, add a javascript line when your page loads that does something like this:

    $('img').each(function(){
      $(this).attr('src', $(this).data('delayedsrc'));
    });
    

提交回复
热议问题