Infinity Scroll & Responsive results.

5 posts by 3 authors in: Forums > CMS Builder
Last Post: July 20, 2012   (RSS)

Re: [Toledoh] Infinity Scroll & Responsive results.

By Jason - July 19, 2012

Hi,

Since screen width is client side, you'll need to use some javascript to detect it. See here for an example (http://www.w3schools.com/jsref/prop_screen_width.asp).

If you need this to affect the number of images being returned by CMS Builder, what you'll need to do is to detect the screen width, and then send that back to the server through a jQuery call to get the content from the database.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Toledoh] Infinity Scroll & Responsive results.

By Dave - July 20, 2012

Hi Tim,

Basically you need to capture the screen width in javascript and then calculate (in Javascript or PHP) how many results per page and pass that back as well. How do you specify the "next page" url for the "Infinite Scroll" widget?

I'd start with outputting to the screen the "next page" url with the screen width included. A starting point might be:

<script type="text/javascript">
document.write("nextpage_viewer.php?width=" + screen.width + "&other=params&go=here");
</script>


Then, before your getRecords() call have some PHP code like this:

// get perPage for Inifinite-Scroll based on supplied screen width
$width = @$_REQUEST['width'];
if ($width >= 960) { $perPage = 80; }
elseif ($width >= 768) { $perPage = 48; }
elseif ($width >= 480) { $perPage = 24; }
elseif ($width >= 320) { $perPage = 16; }
else { $perPage = 8; }


Then pass that to getRecords() like this:

'perPage' => $perPage,

Note, that's all untested code, but should serve as a starting point.

Hope that helps! Let me know how it goes and any other questions. Thanks!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Infinity Scroll & Responsive results.

By Toledoh - July 20, 2012

Thanks guys, that's a great start. I'll let you know how I go!
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Infinity Scroll & Responsive results.

By Dave - July 20, 2012

Good luck. I just realized screen.width is going to give you the fixed screen width, not the browser width. Here's a page on getting browser width:
http://stackoverflow.com/questions/1038727/how-to-get-browser-width-using-javascript-code
Dave Edis - Senior Developer
interactivetools.com