Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
166
rated 0 times [  168] [ 2]  / answers: 1 / hits: 17981  / 15 Years ago, thu, august 27, 2009, 12:00:00

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:





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



This doesn't work (tested in ff3.5, safari 3-4). The images is getting loaded anyway, i dont get it.



For example this plugin, www.appelsiini.net/projects/lazyload, is doing the exact same thing, removing the src attribute on page load.



What am i missing?



EDIT: I added a test page here: http://dev.bolmaster2.com/dev/lazyload-test/
I first remove the src attribute completely, then after 5 seconds I add it with the original image. Still doesn't work, at least firebug says the images get loaded at start, is firebug to trust?


More From » jquery

 Answers
12

I think the problem is that you are emptying the 'img' attribute, not the 'src'.



If you are testing this on a local page, then your local images may be loading too fast. Or maybe they are taken directly from browser cache. Try checking if the image is already loaded before emptying its 'src'.


[#98825] Friday, August 21, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brodyfrancisi

Total Points: 1
Total Questions: 102
Total Answers: 89

Location: Marshall Islands
Member since Mon, May 31, 2021
3 Years ago
brodyfrancisi questions
;