"newElements"如何在Javascript中运行?

Max*_*s S 1 javascript jquery

$container.infinitescroll({
        navSelector  : "div.navigation",
        nextSelector : "div.next-page a:first",   
        itemSelector : "#posts-container div.post",
        bufferPx     : 80
        },
        function( newElements ) {
            var $newElems = $ ( newElements );
            $container.masonry( 'appended', $newElems );
        }
);
Run Code Online (Sandbox Code Playgroud)

在实现infiniteScroll插件时,我newElements实际上并没有真正知道它是什么.在提供的代码中,我newElements作为参数传入,但它没有在上面的任何地方声明.但是,功能正常; 新的帖子元素存储在$newElems.

当我使用时newElements,我是否方便地将所有新添加的元素调用到DOM中?

Ben*_*enM 5

newelementsJavaScript中没有任何内容.它是一个在加载新项时传递给回调函数的变量.

您应该阅读InfiniteScroll的文档,它清楚地详细说明了这个函数:

function(arrayOfNewElems){

     // optional callback when new content is successfully loaded in.

     // keyword `this` will refer to the new DOM content that was just added.
     // as of 1.5, `this` matches the element you called the plugin on (e.g. #content)
     //                   all the new elements that were found are passed in as an array
}
Run Code Online (Sandbox Code Playgroud)

您可以为回调参数指定任何名称,但它将包含新元素的数组.