无限滚动 jQuery & Laravel 5 分页
Infinite Scroll jQuery & Laravel 5 Paginate
我成功从 Controller 返回数据
public function index()
{
$posts = Post::with('status' == 'verified)
->paginate(30);
return view ('show')->with(compact('posts'));
}
此外,我已成功显示我视图中的所有内容:
<div id="content" class="col-md-10">
@foreach (array_chunk($posts->all(), 3) as $row)
<div class="post row">
@foreach($row as $post)
<div class="item col-md-4">
<!-- SHOW POST -->
</div>
@endforeach
</div>
@endforeach
{!! $posts->render() !!}
</div>
到目前为止一切正常。
然而,我根本没有得到官方文档。什么是“div.navigation
”和“#content div.post
”?在我的情况下它们应该是什么?
Snippet From Documentation:
$('#content').infinitescroll({
navSelector : "div.navigation",
// selector for the paged navigation (it will be ?>hidden)
nextSelector : "div.navigation a:first",
// selector for the NEXT link (to page 2)
itemSelector : "#content div.post"
// selector for all items you'll retrieve
});
编辑:我的Javascript到目前为止
$(document).ready(function() {
(function() {
var loading_options = {
finishedMsg: "<div class='end-msg'>Congratulations! You've reached the end of the internet</div>",
msgText: "<div class='center'>Loading news items...</div>",
img: "/assets/img/ajax-loader.gif"
};
$('#content').infinitescroll({
loading: loading_options,
navSelector: "ul.pagination",
nextSelector: "ul.navigation a:first",
itemSelector: "#content div.item"
});
});
});
[<[1]2]3]>] 部分在页面底部创建,但无限滚动不起作用。此外,我在控制台中没有收到任何日志或错误。
首先你需要在结束后像这样添加分页本身 #content
div:
{!! $posts->render() !!}
这将输出如下内容:
<ul class="pagination"><li><a>...</a></li>
要覆盖分页展示器,请查看 。
那么您的配置如下所示:
$(document).ready(function() {
var loading_options = {
finishedMsg: "<div class='end-msg'>Congratulations! You've reached the end of the internet</div>",
msgText: "<div class='center'>Loading news items...</div>",
img: "/assets/img/ajax-loader.gif"
};
$('#content').infinitescroll({
loading: loading_options,
navSelector: "ul.pagination",
nextSelector: "ul.pagination a:first",
itemSelector: "#content div.item"
});
});
基本上,无限滚动器会为您调用分页链接,因此需要知道所有内容的位置以便将它们放在一起。
我成功从 Controller 返回数据
public function index()
{
$posts = Post::with('status' == 'verified)
->paginate(30);
return view ('show')->with(compact('posts'));
}
此外,我已成功显示我视图中的所有内容:
<div id="content" class="col-md-10">
@foreach (array_chunk($posts->all(), 3) as $row)
<div class="post row">
@foreach($row as $post)
<div class="item col-md-4">
<!-- SHOW POST -->
</div>
@endforeach
</div>
@endforeach
{!! $posts->render() !!}
</div>
到目前为止一切正常。
然而,我根本没有得到官方文档。什么是“div.navigation
”和“#content div.post
”?在我的情况下它们应该是什么?
Snippet From Documentation:
$('#content').infinitescroll({ navSelector : "div.navigation", // selector for the paged navigation (it will be ?>hidden) nextSelector : "div.navigation a:first", // selector for the NEXT link (to page 2) itemSelector : "#content div.post" // selector for all items you'll retrieve });
编辑:我的Javascript到目前为止
$(document).ready(function() {
(function() {
var loading_options = {
finishedMsg: "<div class='end-msg'>Congratulations! You've reached the end of the internet</div>",
msgText: "<div class='center'>Loading news items...</div>",
img: "/assets/img/ajax-loader.gif"
};
$('#content').infinitescroll({
loading: loading_options,
navSelector: "ul.pagination",
nextSelector: "ul.navigation a:first",
itemSelector: "#content div.item"
});
});
});
[<[1]2]3]>] 部分在页面底部创建,但无限滚动不起作用。此外,我在控制台中没有收到任何日志或错误。
首先你需要在结束后像这样添加分页本身 #content
div:
{!! $posts->render() !!}
这将输出如下内容:
<ul class="pagination"><li><a>...</a></li>
要覆盖分页展示器,请查看
那么您的配置如下所示:
$(document).ready(function() {
var loading_options = {
finishedMsg: "<div class='end-msg'>Congratulations! You've reached the end of the internet</div>",
msgText: "<div class='center'>Loading news items...</div>",
img: "/assets/img/ajax-loader.gif"
};
$('#content').infinitescroll({
loading: loading_options,
navSelector: "ul.pagination",
nextSelector: "ul.pagination a:first",
itemSelector: "#content div.item"
});
});
基本上,无限滚动器会为您调用分页链接,因此需要知道所有内容的位置以便将它们放在一起。