Jump to content

adding items to a div each time the users scrolls down to the end of the div


phdphd

Recommended Posts

Hi All,
On my webpage I have a div that scrolls vertically, with a list of items in it. The items in the div come from a php array. I noticed that the building of the div gets slow when there are many items in the array. Since the user might not be interested by the contents of the div, I am considering filling the div by only adding items to it each time the user scrolls down to the end of the div. So basically, each time the user would reach the bottom of the div, the JS code would add items from the php array to the list in the div. Is it possible to implement this ?
Thanks.

Yes, you would listen for the scroll event, and check what position they are scrolled to. If they have reached the bottom, send an ajax request to get more items then add them to the div.

 

If you're using jQuery it will simplify the job significantly compared to using the raw api's I linked above.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.