views:

67

answers:

2

I want to lazy-load the results of my Youtube API search, so that as the user scrolls down, Youtube players are being added to the page. It seems that the lazy loading plugins are focused on images, but what I will be loading is just HTML, because I'm using iFrames to load the Youtube players (as per the new Youtube embed style). How can I do this in jQuery? Thanks for reading.

A: 

If I understand you correctly you need something like:

$( "body").scroll( function() {
   $( "#youtubeDiv").load( "youtube.html");
});

Instead of load you can append html fragment.

Artem Barger
Shall I guess what's wrong with my answer?
Artem Barger
A: 

You can use the .scroll() and .ScrollTop() functions to detect if you are at the current bottom of the page/scroll. if so, append the next set of iframes to the main element. This also means you need to keep track of the already loaded elements and the available (to be loaded) elements. The latter should be the result of your search.

Milo
@Artem Barger, I didn't rate you're answer but to answer your question in the comment:You're code would add "youtube.html" anytime "scroll" is called which would be a _lot_ of times.
Milo