14

I'm using the great infinite-scroll plugin- http://www.infinite-scroll.com/infinite-scroll-jquery-plugin/

But on larger screen resolutions there's not enough posts to display a scroll bar so the infinite-scroll never gets triggered. Wondered if these a way around this without having a large number of initial posts.

Guessing some kind of if statement to check browser height etc. But how do i then trigger the infinite-scroll if it returns true.

Any ideas

Thanks

Ben

Ben
  • 972
  • 3
  • 12
  • 22

3 Answers3

15

One way to go for a quick check would be:

// Force 'retrieve' for next page if window is taller than document
if($(window).height() >= $(document).height()){
$wall.infinitescroll('retrieve');
};

Guess you may need to turn this into a function for multiple 'retrieve' if needed until window is not taller than the document.

Luigi
  • 384
  • 2
  • 15
4

For newer versions of infinitescroll, set the option

prefill: true

This solution was created and discussed on this issue on github.

Philipp Zedler
  • 1,520
  • 1
  • 13
  • 32
2

I know question is old, but this will help many of you.

@Luigi answer is good, but what if loading content once to show scrollbar is not enough?

This should do it best

var no_scrollbar_workaround = setInterval(function checkVariable() {

           if($(window).height() >= $(document).height()) {
                    jsonloader(); //here you put your function for more content
            } else {
                    clearInterval(no_scrollbar_workaround);
            }
}, 1000);

This will run several times, until needed to actually show scroll bar.

You can test this function and see all it's glory when you zoom out page as far as you can with Ctrl + -.

You will see call for new content until scrollbar is shown.

Luka
  • 379
  • 4
  • 14