2

好吧,我正在尝试使 Masonry 使用无限滚动,我找到了官方appended方法(http://desandro.github.io/masonry/demos/infinite-scroll.html)并试图让它在我的代码上工作. 但我需要更改一些$to jQuery,现在它可以像砖石一样工作,但无限滚动仍然无法工作,我想知道我是否忘记了jQuery要从我的代码中更改为的美元符号,请帮助我

<script >
  jQuery(function(){

    var $container = jQuery('ul.products');

    $container.imagesLoaded(function(){
      $container.masonry({
        itemSelector: 'li.product',
        columnWidth : 295,
    isFitWidth: true,
        gutterWidth : 2
      });
    });

    $container.infinitescroll({
      navSelector  : '#page-nav-woo',    // selector for the paged navigation 
      nextSelector : '.next',  // selector for the NEXT link (to page 2)
      itemSelector : 'li.product',     // selector for all items you'll retrieve
      loading: {
          finishedMsg: 'No more pages to load.',
          img: 'http://i.imgur.com/6RMhx.gif'
        }
      },
      // trigger Masonry as a callback
      function( newElements ) {
        // hide new items while they are loading
        var $newElems = jQuery( newElements ).css({ opacity: 0 });
        // ensure that images load before adding to masonry layout
        $newElems.imagesLoaded(function(){
          // show elems now they're ready
          $newElems.animate({ opacity: 1 });
          $container.masonry( 'appended', $newElems, true ); 
        });
      }
    );

  });
</script>
4

2 回答 2

2

好的,我的问题的解决方案是这样的:

1.我安装了wp插件

2.新增回调部分:

 var $newElems = jQuery( newElements ).css({ opacity: 0 });
        // ensure that images load before adding to masonry layout
        $newElems.imagesLoaded(function(){
          // show elems now they're ready
          $newElems.animate({ opacity: 1 });
          $container.append( $newElems ).masonry( 'appended', $newElems, true );
        });

3.行为:砌体

它就像一个魅力!谢谢大家!

于 2013-10-31T15:51:19.840 回答
0

或者,您可以将脚本包装在闭包中:

(function($) {
    // i can use $ instead of jQuery
} (jQuery));

或者

(function(jQuery) {
    // i can use jQuery instead of $
} ($));
于 2013-10-31T15:54:23.960 回答