【问题标题】:Infinite Scroll on ajax loaded content在ajax加载的内容上无限滚动
【发布时间】:2014-03-01 03:14:29
【问题描述】:

我在比方说 page-a.php 上执行 WP_Query,该页面有一个名为 target 的 div,page-b.php 正在加载到该 div 中。 page-a 是自定义模板,page-b 是存档页面。

以页面A的结构为例:

<body>
<div id="wrap">
<div class="target">
  while
   <div class="post">
     <h1>Title</h1>
     <p>Description</p>
   </div>
  endwhile
   <div class="pagination"></div>
</div>
</div>
</body>

在 page-b 上,我只在常规 wp 循环中包含 div。

现在是 jQuery:

 $(window).load(function() {
                $('.target').infinitescroll({
                  navSelector  : ".navigation",           
                                 // selector for the paged navigation (it will be hidden)
                  nextSelector : ".navigation a.next",    
                                 // selector for the NEXT link (to page 2)
                  itemSelector : ".post",          
                                 // selector for all items you'll retrieve
                  debug : true,
                  loading: {
                      finishedMsg: '<div class="alert alert-info" style="margin-top:50px"><p class="center">All posts were loaded</p></div>',
                      img: '',
                      msg: null,
                      msgText: "<p style='text-align:center; margin-top:50px;'><i style='font-size:60px; color:#babfc8'class='fa fa-cog fa-spin'></i></p>"
                    }

                }, function(arrayOfNewElems){
                 $('.post').animate({"opacity":"1","max-height":"150px","padding":"15px 8px"},800, "jswing");
                } 
                );

     });

-如果我在 page-a.php 上调用该脚本,那么一旦将 page-b 内容放置在上面,它将只对其起作用

-如果我调用 page-a.php 和 page-b.php 它首先可以工作,然后当第一个 ajax 内容被加载然后(如果我应用新的过滤器)它将无法工作。

-如果我在我的 ajax 响应函数上调用脚本,它将工作一次,然后如果我应用另一个过滤器并且目标 div 刷新内容,我会得到 ​​p>

未捕获的类型错误:无法调用 null 的方法 'appendTo'

页面上存在名为(.target 和 .post)的 div 类。

我到底做错了什么。谢谢。

PS:如果您需要查看真实脚本,请告诉我,我会提供。

【问题讨论】:

    标签: ajax wordpress pagination infinite-scroll


    【解决方案1】:

    我认为你需要这个:http://www.247techblog.com/implement-infinite-scroll-functionality-wordpress-wp-ajax-function/ 只需要调用一个 wp ajax 函数

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-31
      • 1970-01-01
      • 2015-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多