如何使用 javascript 更改无限滚动的路径

How to change the path of infinitescroll with javascript

我最近在我的网站上安装了 infinitescroll 插件以更轻松地加载内容,但我遇到了一个问题:

我有一个过滤器,当您在列表中 select 时,它可以按流派、数据、国家等对所有帖子进行排序。它是用 ajax 制作的,问题是应用此过滤器时的路径必须与最初不同,因此当它加载内容时,它会在不应用过滤器的情况下加载帖子,我需要的是更改无限滚动路径单击以订购帖子时。

Infinitescroll 插件:

$('.catalogue').infiniteScroll({
      path: '.pagination__next', //it gets the href attribute from .pagination__next and of course it is changed in the html code when the filter is applied but in the js code is not.
      append: '.item',
      button: '.view-more-button',
     scrollThreshold: false,
      history: false,
    });

你可以试试用函数这样设置路径

$('.catalogue').infiniteScroll({
    path: function(){
        return $('.pagination__next').attr('href');
    },
    append: '.item',
    button: '.view-more-button',
    scrollThreshold: false,
    history: false,
    });

或者您可以在路径函数中应用您想要的任何其他逻辑以满足您的需要。