使用infinite-scroll.js库加载内容后进行回调

问题描述 投票:1回答:1

是否可以在使用infinite-scroll.js库加载后调用函数?

我见过一个在init上调用的函数:

onInit: function() {
    this.on( 'load', function() {
       var ancho = parseFloat($('.imagen').innerWidth());
       $('.normal img').css("width", ancho);
       $('.hover img').css("width", ancho);
     });
 }

https://infinite-scroll.com/options.html#oninit

加载内容后是否可以调用函数?

编辑

以下是以下答案的更新代码。

var inf = $('.col-trabajos').infiniteScroll({
    path: '.nav-previous a',
    append: '.article',
    history: false,
    hideNav: '.nav-links',
});

// callback
inf.on( 'append.infiniteScroll', function( event, response, path, items ) {
   var ancho = $('.imagen').innerWidth();
   $('.normal img').css("width", ancho);
   $('.hover img').css("width", ancho);
});
javascript jquery infinite-scroll
1个回答
1
投票

您可以在此库中收听该选项(以及更多),

这是“追加”功能的示例,它是:

项目元素附加到容器后触发

// jQuery
$container.on( 'append.infiniteScroll', function( event, response, path, items ) {
  console.log( 'Loaded: ' + path );
});

// vanilla JS
infScroll.on( 'append', function( response, path, items ) {...});

看看这个页面:https://infinite-scroll.com/events.html#append

© www.soinside.com 2019 - 2024. All rights reserved.