Stop loading of images with javascript (lazyload)?

前端 未结 9 2376
醉梦人生
醉梦人生 2020-12-19 08:03

I am trying to stop the loading of images with javascript on dom ready and then init the loading whenever i want, a so called lazy loading of images. Something like this:

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-19 08:36

    I don't know if you have written wrong in the question but the attribute the you should set to an empty string is "src" not "img". Try this:

    $(document).ready(function () {
      var images = $('img');
      $.each(images, function() {
        $(this).attr('src', '');
      });
    });
    

提交回复
热议问题