trigger infinite-scroll when there's not enough content for scroll bar on page load
Asked Answered
A

3

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

Afterburning answered 12/7, 2012 at 16:6 Comment(0)
P
16

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.

Pogonia answered 2/8, 2012 at 14:46 Comment(1)
This should be chosen as the answer. Thanks Luigi!Dunstable
A
4

For newer versions of infinitescroll, set the option

prefill: true

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

Air answered 31/5, 2013 at 0:15 Comment(4)
It doesn't work for me. It stays the same way, without vertical scroll and new items aren't added.Psychotomimetic
Make sure you are using the newest version of the infinitescroll plugin.Air
I'm using 2.0b2.120519, still nothing. The other answer to this question works.Psychotomimetic
Be careful though about doing prefill if you ever don't have enough to fill the page: github.com/metafizzy/infinite-scroll/issues/797Fant
H
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.

Hawger answered 27/4, 2017 at 16:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.