douyuanliao8815 2017-05-22 19:47
浏览 52
已采纳

Laravel 5.4 + jScroll.js不能正常工作

I'm trying to implement an infinite scrolling based on this tutorial.

Couldn't be simpler, right? well... It's not working. This is my code here:

In the route file (I didn't put it in a controller because was a simple test)

Route::get('/', function(){

$articles = \App\Article::paginate(1);

return view('home')->with('articles', $articles);

});

In home.blade.php

<div class="infinite-scroll">
@foreach($articles as $article)
    <article class="post">
        <header>
            <div class="title">
                <h2>{{ $article->title }}</h2>
            </div>
        </header>
    </article>
@endforeach
</div>

{{ $articles->links() }}

At the bottom of that same file

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.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: '.infinite-scroll',
            callback: function() {
                $('ul.pagination').remove();
            }
        });
    });
</script>

There's absolutely nothing in the console. Like nothing is happening.

I'm missing something, but I don't know what. Do you see something wrong? Thanks!

Ps. I also changed contentSelector: '.infinite-scroll' to contentSelector: 'div.infinite-scroll',. But nothing.

  • 写回答

2条回答 默认 最新

  • dryk50495 2017-05-22 20:12
    关注

    Your pagination is outside the infinite-scroll.

    Try

    <div class="infinite-scroll">
    @foreach($articles as $article)
        <article class="post">
            <header>
                <div class="title">
                    <h2>{{ $article->title }}</h2>
                </div>
            </header>
        </article>
    @endforeach
    {{ $articles->links() }}
    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭