2

我正在使用 jQuery Masonery 实现无限滚动:

$(函数(){

var $container = $('#container');

$container.imagesLoaded(function(){
  $container.masonry({
    itemSelector: '.box',
    columnWidth: 100
  });
});

$container.infinitescroll({
  navSelector  : '#page-nav',    // selector for the paged navigation 
  nextSelector : '#page-nav a',  // selector for the NEXT link (to page 2)
  itemSelector : '.box',     // 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 = $( 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 ); 
    });
  }
);
   }); 

这是最简单的示例,但我想知道是否可以使用 AJAX 获取动态内容,而不仅仅是示例中显示的静态页面:

<nav id="page-nav">
  <a href="../pages/2.html"></a>
</nav>

谢谢你的帮助!

4

1 回答 1

2

这很简单。请按照以下步骤操作。

更改导航链接:

<nav id="page-nav">
  <a href="../pages/AjaxSource.php?no=2"></a>
</nav>

你的 AjaxSource.php 应该是这样的

<?php 
$pageNo= $_GET['no'];
?>

<?php if ($pageNo==2){?>

<div id="container" class="transitions-enabled clearfix">

    <div class="box photo col3">
      <a href="http://www.flickr.com/photos/nemoorange/5013039951/" title="Stanley by Dave DeSandro, on Flickr"><img src="http://farm5.static.flickr.com/4113/5013039951_3a47ccd509.jpg" alt="Stanley" /></a>
    </div>

    <div class="box photo col3">
      <a href="http://www.flickr.com/photos/nemoorange/5013039951/" title="Stanley by Dave DeSandro, on Flickr"><img src="http://farm5.static.flickr.com/4113/5013039951_3a47ccd509.jpg" alt="Stanley" /></a>
    </div>

</div>

<?php } ?>
于 2013-02-26T09:55:30.890 回答