Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to retrieve first 2 record when scroll 200px in page . after that when scroll 400px ,retrieve second 2 record in database


What I have tried:

i am tried some code but it dose not work correctly can anyone give me solution for this problem
Posted
Updated 2-Jul-18 1:00am
v2

Consider using one of the infinite scroll jQuery libraries and pull the data as needed. Instead of writing the code yourself, that library can handle the scrolls and so on. Mostly what happens is that events are triggered — computers are accurate in calculations, and users might scroll at different speeds. These libraries can help in pulling data sequentially as needed.

One of such libraries: Infinite Scroll[^]
 
Share this answer
 
Let's break down your problem first.

1. Use paging (OFFSET/FETCH) to fetch records from DB
Example: Pagination with OFFSET / FETCH : A better way[^]

2. Check your current position with window.scroll() method
$(window).scroll(function() {
    if($(window).scrollTop() == $(document).height() - $(window).height()) {
           // ajax call get data from server and append to the div
    }
});

Example: Load data on page scroll using jquery - YouTube[^]


KR
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900