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

标签 javascript jquery infinite-scroll

是否可以在使用 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);
});

最佳答案

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

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

Triggered after item elements have been appended to the container

// 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

关于javascript - 使用 infinite-scroll.js 库在内容加载后执行回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49065918/

相关文章:

javascript - 用随机字母替换字符串中的任意 3 个字母

javascript - Promise.all 对遍历生成器无效

JavaScript:DOM 加载事件、执行顺序和 $(document).ready()

javascript - 我可以在 Internet Explorer 中将整个 HTML 文档加载到文档片段中吗?

ionic-framework - ionic 无限滚动循环永远调用无限回调

firebase - 使用 FlatList (React Native) 时出现错误 : Warning: Each child in an array or iterator should have a unique "key" prop. %s%s

javascript - 在 Masonry 的 container.append 上出现错误 Uncaught TypeError : Object has no method filter

javascript - 使用 PHP/JS 执行操作

javascript - 脚本未对齐表

jquery - float div - 不在一行中对齐