Scoop7's avatar
Level 13

Laravel 5.4 + jScroll.js not working(no console errors)

I followed this tutorial with very close detail -> https://laraget.com/blog/implementing-infinite-scroll-pagination-using-laravel-and-jscroll

But my the infinite scroll doesn't seem to work - nothing happens when I scroll down through the entire page(even no console errors). I only have one item loaded that is loaded together when the page is loaded.

My Controller:

 public function photo()
{
    $photos = Photo::where('user_id', Auth::user()->id)
        ->paginate(1);
    return view('reports/photo')->with('photos',$photos);
}

View:

<div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="infinite-scroll">
                    @foreach($photos as $photo)
                        <h4 class="media-heading">{{ $photo->photo_link }}
                            <small>{{ $photo->created_at->diffForHumans() }}</small>
                        </h4>
                        {{ $photo->photo_at }}
                        <hr>
                    @endforeach

                    {{ $photos->links() }}
                </div>
            </div>
        </div>
    </div>

at the same file bottom:

      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
                    <script src="/js/bootstrap.min.js"></script>
                    <script src="https://cdnjs.cloudflare.com/ajax/libs/jscroll/2.3.7/jquery.jscroll.min.js"></script>

<script type="text/javascript">

    $('ul.pagination').hide();
    $(function() {
        $('.infinite-scroll').jscroll({
            autoTrigger: true,
            debug: true,
            loadingHtml: '<img class="center-block" src="/images/loading.gif" alt="Loading..." />',
            padding: 0,
            nextSelector: '.pagination li.active + li a',
            contentSelector: 'div.infinite-scroll',
            callback: function() {
                $('ul.pagination').remove();
            }
        });
    });
</script>
0 likes
6 replies
rob897's avatar

Assuming you have more than 1 picture for that user_id

Scoop7's avatar
Level 13

@rob897 Yes, I have several... With normal links - in out of box Laravel 5.4 pagination everything worked.

rob897's avatar

Looks like a good idea, I will see if I can get it working on one of my projects.

Scoop7's avatar
Level 13

@rob897 Please give some feedback if you were successful in making the infinitive scroll feature to work!

rob897's avatar

Ok this works for me in my application, just that I had to remove the document ready function of jquery as I load my scripts at the bottom of the page.. So my javascripts looks like this:

<script type="text/javascript">

    $('ul.pagination').hide();
    $('.infinite-scroll').jscroll({
            autoTrigger: true,
            debug: true,
            loadingHtml: '<img class="center-block" src="/images/loading.gif" alt="Loading..." />',
            padding: 0,
            nextSelector: '.pagination li.active + li a',
            contentSelector: 'div.infinite-scroll',
            callback: function() {
                $('ul.pagination').remove();
            }
    });
</script>
Scoop7's avatar
Scoop7
OP
Best Answer
Level 13

Just want to give an update: My code was fine. I had some 3rd party css(bootstrap-light-dashboard.css~) that was hiding the newly loaded records... Solved.

Please or to participate in this conversation.