Infinity Scroll & Responsive results.
5 posts by 3 authors in: Forums > CMS Builder
Last Post: July 20, 2012 (RSS)
By Toledoh - July 18, 2012
Sorry for the long post...
I'm implementing Infinite Scroll (http://www.infinite-scroll.com/) on a site, that displays a "wall of images"; square product images that fill the browser window in a tile effect. The number of images could be heaps, so I need some form of pagination.
Infinite scroll can be configured to display X results per page, then when the page is scrolled to the bottom, the next X appear =rather than clicking through to the next page.
However, the site is also responsive, so on a mobile it displays a grid of 1 image across, landscape 2 images across, up to 10 images across on a wide screen.
I want to show a grid 10 by 8 on the wide screen, so 80 results per page, by only 1 by 8 on the mobile, so 8 results per page.
Can anyone advise me on how to change the "results per page" based on the screen width?
kind of like:
@media screen and (min-width: 960px) {
'perPage' => '80',}
}
@media only screen and (min-width: 768px) and (max-width: 959px) {
'perPage' => '48',}
}
@media only screen and (min-width: 480px) and (max-width: 767px) {
'perPage' => '24',}
}
@media only screen and (min-width: 320px) and (max-width: 479px) {
'perPage' => '16',}
}
@media screen and (min-width: 0px) and (max-width: 319px) {
'perPage' => '8',}
}
thanks!
Tim (toledoh.com.au)
Re: [Toledoh] Infinity Scroll & Responsive results.
By Jason - July 19, 2012
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
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!
interactivetools.com
Re: [Dave] Infinity Scroll & Responsive results.
By Toledoh - July 20, 2012
Tim (toledoh.com.au)
Re: [Toledoh] Infinity Scroll & Responsive results.
By Dave - July 20, 2012
http://stackoverflow.com/questions/1038727/how-to-get-browser-width-using-javascript-code
interactivetools.com