1

our site has few pages where many images shown. over the slow internet page load long time to load fully along with images. i search google for having jquery solution which will download image on demand when user scroll down the page. i found a jquery library called lazyload the url is http://www.appelsiini.net/projects/lazyload

this plugin is good but my page content along with images populated from database. database content is inserted from a html editor. i read the lazyload and found that

1) <img class="lazy" src="img/grey.gif" data-original="img/example.jpg" >

image src will has different images and actual image path will be written to data-original property which is not possible for my page because i said that my page content is developed by html editor. so i need help that how to customize the library as a result my image tag will be as is like normal image tag like <img class="lazy" src="img/example.jpg" > but it still work. if it is not possible by this library then suggest me any other libary which will download only those images which are in browser viewport. i am trying to say that my image tag will be <img class="lazy" src="img/example.jpg" > but library will download only those images which are in browser viewport. please help. or give me any sample code by which few images will downloaded and rest will download when user scroll down. thanks.

8
  • You can try to find an old release of lazyload (v 1.5.0). This version works without data attributes. Commented Jun 13, 2012 at 13:39
  • i found that we have to give the same data-original attribute in version of lazyload (v 1.5.0). as a proof jontai.me/blog/2012/04/lazy-loading-images-on-a-wordpress-blog github.com/p0is0n/jquery.lazyload any suggestion?? Commented Jun 13, 2012 at 13:53
  • the problem is i can not change my markup....need suggestion. thanks Commented Jun 13, 2012 at 13:53
  • At the first link, there is a example how you can upgrade 1.5 to 1.7. At the second link you should take a look at the test.html, where you can see no data attributes at the image tags Commented Jun 13, 2012 at 13:59
  • i notice actual image url is tagged with title attribute....title="t3.gstatic.com/…" my problem is i can not change my html. i can not add title attribute to my image tag. please need suggestion. Commented Jun 13, 2012 at 14:06

1 Answer 1

3

Before calling

$("img.lazy").lazyload();

Add lazy class and the data-original attribute to all images of the database content. e.g. You have database contents in a div with id "content".

$("#content img").each(function() {
    $(this).addClass('lazy');
    $(this).attr('data-original', $(this).attr('src'));
});

Hope it will help.

Sign up to request clarification or add additional context in comments.

5 Comments

the problem is i can add data-original attribute....i can not change my html markup. so now tell me how to use this library to load image on demand....or suggest any other library to load image on demand without changing my markup??
This solution only touch your image tags at client side / on the fly so you don't have to change your markup..or am i wrong?
please tell me what u trying to say
I guess, we have to change the image tag (add class or css) to stop the browser to create request for it.
At the end, add this: );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.