Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-10-2009, 01:31 PM   PM User | #1
Crul
New to the CF scene

 
Join Date: Nov 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Crul is an unknown quantity at this point
Loading More Entries According to the Users Screen Size

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():

Code:
start = 0;
getMaxEntries();
    
var docHeight = document.body.clientHeight;
while(docHeight < window.innerHeight) {
  if(start > 0) {
    loadEntries();
    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.

Thanks,

Sid
Crul is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:33 PM.


Advertisement
Log in to turn off these ads.