1

I created a database where I store all the images' names so that I can retrieve it later on. To retrieve the images' names, I use ajax and bind it with <img> tag:

$.post('image_name.php',{id:id}, function(data){
   $('#container').html('<img src="img/'+data+'">');
});

Everything works great. But what I noticed was, all the images shows up at the same time which slows the process a little bit. Therefore, I am thinking that the best way to handle this issue is to use lazy load. I want any data that is ready to be displayed.... but I do not know how to.

Additonal Info: I am trying to create a list of thumbnails. Just like the Imgur sidebar (https://i.sstatic.net/BbtPn.jpg)

5
  • how about using a jQuery plugin? appelsiini.net/projects/lazyload Commented May 4, 2013 at 21:51
  • I am not trying to lazy load the image, I am trying to lazy load the data I am retrieve from my database Commented May 4, 2013 at 22:03
  • ok...and to clarify, you want to lazy load image src's which are not visible on screen? Commented May 4, 2013 at 22:06
  • i am trying to lazy load this data "function(data)". lazy load image is a different topic. Commented May 4, 2013 at 22:08
  • apply your code when your images are supposed to be loaded, or if you only want to lazy load src data, only set that data like $("img").attr("src",data) Commented May 4, 2013 at 22:10

1 Answer 1

1

If you plan to create a list with left / right button:

  1. With ajax fetch array of next 6 images. Only names or ids.
  2. On ajax success:

Whole idea is:

onsuccess:
    $(whatyougotfromajax).each(function(index, value)
    {
        $.oneTime(index * Interval * 1000, function()
        {
            $('#block').append('<img src="sth.php?Id=' + value + '">');
        });
    });

I im not sure... Not, I'm sure it is not work in this way, but you've got the idea

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

Comments

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.