有没有带有加载更多按钮的无限滚动插件?

发布于 2024-12-25 07:53:45 字数 1539 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

撩人痒 2025-01-01 07:53:45

来自 jQuery 无限滚动插件的 文档页面

在 1.4 中,您可以在以下位置触发下一页内容的加载:
将要。您将首先取消绑定默认行为。然后触发
只要您愿意,就可以下次拉动。

// unbind normal behavior. needs to occur after normal infinite scroll setup.
$(window).unbind('.infscr');
// call this whenever you want to retrieve the next page of content
// likely this would go in a click handler of some sort
$(document).trigger('retrieve.infscr');

它应该可以解决你的问题。

From the documentation page of jQuery infinite scroll plugin:

In 1.4 you can trigger the loading of the next page of content at
will. You’ll first unbind the default behavior. And then trigger the
next pull whenever you like.

// unbind normal behavior. needs to occur after normal infinite scroll setup.
$(window).unbind('.infscr');
// call this whenever you want to retrieve the next page of content
// likely this would go in a click handler of some sort
$(document).trigger('retrieve.infscr');

It should solve your problem.

从﹋此江山别 2025-01-01 07:53:45

使用当前版本的无限滚动插件 (2.1.0),您可以在加载元素时暂停,然后恢复并检查是否应在单击按钮(或其他任何内容)时加载新内容:

$('.container').infinitescroll({
        // infinite scroll options
    },
    function(){
        // pause when new elements are loaded
        $('.container').infinitescroll('pause')
    }
);

function resume_infinite_scroll(){
    // resume
    $('.container').infinitescroll('resume')
    // check if new elements should be loaded
    $('.container').infinitescroll('scroll')
}

然后

<button onclick="resume_infinite_scroll()">load more</button>

With current version of Infinite Scroll Plugin (2.1.0), you can just pause when the elements are loaded, and then resume and check if new content should be loaded on a button click (or anything else):

$('.container').infinitescroll({
        // infinite scroll options
    },
    function(){
        // pause when new elements are loaded
        $('.container').infinitescroll('pause')
    }
);

function resume_infinite_scroll(){
    // resume
    $('.container').infinitescroll('resume')
    // check if new elements should be loaded
    $('.container').infinitescroll('scroll')
}

and then

<button onclick="resume_infinite_scroll()">load more</button>
失与倦" 2025-01-01 07:53:45

如果您正在寻找无限滚动,这是一回事,但只是一个“更多”按钮不需要插件。

HTML

<div id="items">
    <!-- Run your query using the page parameter to offset items, then display the items here -->
</div>
<button id="more">More</button>

JS

var page = 0;
$('#more').click(function(){
    page++;
    $('<div/>').appendTo('#items').load('the/same/url/?page='+page+' #items');
});

.load 函数将对提供的 URL 进行 AJAX 调用,并且可选选择器将仅拉出特定的匹配项。在这种情况下,如果显示页面的 ?page 参数控制查询的偏移量以提取所需的项目,则 .loading URL 将在每次调用时附加下一组项目。

当然,您可以创建一个独特的 AJAX 页面,仅返回下一组项目的 HTML 片段,但根据您的架构,它会涉及更多一些。但是,这样做可以节省带宽/执行时间。

If you are looking for an infinite scroll, that's one thing, but just a More button shouldn't require a plugin.

HTML

<div id="items">
    <!-- Run your query using the page parameter to offset items, then display the items here -->
</div>
<button id="more">More</button>

JS

var page = 0;
$('#more').click(function(){
    page++;
    $('<div/>').appendTo('#items').load('the/same/url/?page='+page+' #items');
});

The .load function will make an AJAX call to the URL provided and the optional selector will just pull out that particular matched item. In this case if the ?page parameter to your display page controls the offset to the query to pull the items you want then .loading the URL will append the next set of items every time it is called.

Of course you could make a unique AJAX page that just returns the HTML fragments for the next set of items but it is a little bit more involved depending on your architecture. You will save bandwidth/execution time by doing it, however.

痕至 2025-01-01 07:53:45

基本上你的身体应该有CSS overflow:scroll 并且更多按钮应该使用jquery追加将更多的html附加到你的容器Div -

Basically you body should have the css overflow:scroll and the more button should append more html to you container Div using jquery append - http://api.jquery.com/append/

爱要勇敢去追 2025-01-01 07:53:45

当前的Infinite-scroll v3.0.6接受“单击按钮开始加载”按钮,如手册< /a>

允许页面末尾的按钮开始无限滚动。

var $container = $('.container').infiniteScroll({
  // options...
  // disable loading on scroll
  loadOnScroll: false,
});

var $viewMoreButton = $('.view-more-button');
$viewMoreButton.on( 'click', function() {
  // load next page
  $container.infiniteScroll('loadNextPage');
  // enable loading on scroll
  $container.infiniteScroll( 'option', {
    loadOnScroll: true,
  });
  // hide button
  $viewMoreButton.hide();
});

the current infinite-scroll v3.0.6 accepts a "Click button to start loading" button as stated on the manual

That allow a button at the end of the page to start the infinite scrolling.

var $container = $('.container').infiniteScroll({
  // options...
  // disable loading on scroll
  loadOnScroll: false,
});

var $viewMoreButton = $('.view-more-button');
$viewMoreButton.on( 'click', function() {
  // load next page
  $container.infiniteScroll('loadNextPage');
  // enable loading on scroll
  $container.infiniteScroll( 'option', {
    loadOnScroll: true,
  });
  // hide button
  $viewMoreButton.hide();
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文