Stop loading of images with javascript (lazyload)?

前端 未结 9 2397
醉梦人生
醉梦人生 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:33

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

    This won't work because jQuery is being called after the page has loaded at:

    $(document).ready()

    all this code would be doing is removing the src value after the image has already been called from the server.

提交回复
热议问题