Infinity Scroll & Responsive results.

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

By Toledoh - July 18, 2012

Hi All,

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!
Cheers,

Tim (toledoh.com.au)

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: [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