View Full Version : Loading More Entries According to the Users Screen Size

03-10-2009, 01:31 PM
Basically I have an on scroll feature that loads more entries when a user scrolls down. So I have that working, np there. But the problem is that the scroll bar doesn't show up on the page because the initial number of entries, onPageLoad aren't enough.

onPageLoad, I want to be able to dynamically add more entries according to the users screen size.

The following are the functions I have:

loadEntries() --> xmlhttpRequest that gets the data and appends it on the screen
getMaxEntries() --> xmlhttpRequest that gets the total number of entries that can be retrieved
$(window).scroll(function() --> calls loadEntries()

I also have <body onload="setup()">

setup() --> calls getMaxEntries(), here is where I would like call loadEntries() a few times (according to the screen size)

The only way I could get entries to load dynamically, onPageLoad was via a loop that called loadEntries() but that gave me an unresponsive script error, which I want to avoid.

loadEntries() will always return 20 results each time. I can't make it return 20 results one time and 23 results the next time. Basically I want to call it enough times to fill the whole page with entries so that the scroll bar shows up. So for a larger screen I would need to call loadEntries() a few more times than for a smaller screen. How many times loadEntries() is called depends on screen size.

Basically the goal is to get the scroll bar to show up so that when the user scrolls my onScroll function is called. Without the scrollbar the onScroll function doesn't get called and more entries don't load.

Obviously the number of entries loaded onPageLoad can't be static due to varying user screen sizes.

Basically I was trying to do the following in setup():

start = 0;

var docHeight = document.body.clientHeight;
while(docHeight < window.innerHeight) {
if(start > 0) {
docHeight += 500;

Note: getMaxEntries() sets the value of start. So when getMaxEntries() is called start will hold the number for the total amount of entries.

But the problem is that the above code gives me a unresponsive script error.

Any suggestions to solve this problem would be greatly appreciated.