Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
156
rated 0 times [  161] [ 5]  / answers: 1 / hits: 35843  / 14 Years ago, mon, may 24, 2010, 12:00:00

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 code or applying a class to it to force it to load only after everything else is loaded?


More From » jquery

 Answers
139

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



<img src=# data-delayedsrc=/img/myimage.png />


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



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

[#96698] Thursday, May 20, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
darrell

Total Points: 109
Total Questions: 113
Total Answers: 113

Location: Zambia
Member since Sat, Oct 31, 2020
4 Years ago
darrell questions
Mon, May 9, 22, 00:00, 2 Years ago
Sat, Mar 19, 22, 00:00, 2 Years ago
Sat, Oct 10, 20, 00:00, 4 Years ago
;