在Ajax加载的内容上进行无限滚动

在Ajax加载的内容上进行无限滚动

本文介绍了在Ajax加载的内容上进行无限滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对page_a.php进行WP_Query,该页面具有一个名为target的div,其中将page-b.php加载到其中.页面-a是自定义模板,页面-b是存档页面.

I'm doing a WP_Query on let's say page-a.php, that page has a div called target where page-b.php is being loaded into. Page-a is a custom template and page-b is an archive page.

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

在页面b上,我仅包含<发布>和<常规wp循环中的pagination> divs.

On page-b I only include the < post > and < pagination > divs within a regular wp loop.

现在使用jQuery:

Now the 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内容放在

-If I call that script on page-a.php will only work on it, once page-b content is placed on

-如果我先调用page-a.php和page-b.php,则它在第一个上运行,然后在第一次加载ajax内容时,然后(如果我应用新的过滤器)它将不起作用.

-If I call on page-a.php and page-b.php it works on first, then when first ajax content is loaded and then (if I apply a new filter) it won't work.

-如果我在ajax响应函数上调用该脚本,它将运行一次,然后,如果我应用另一个过滤器并且目标div刷新了内容,则会得到

-If I call the script on my ajax response function it will work once, then if I apply another filter and target div refreshes content, I get the

页面上存在

名为(.target和.post)的div类.

div classes called (.target and .post) are present on the page.

我到底在这里做错了什么.谢谢.

What the hell am I doing wrong here. Thanks.

PS:如果您需要看一下真实的脚本,请告诉我,我会提供的.

PS: If you need to take a look at the real scripts let me know and I will provide.

推荐答案

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

I think you need this : http://www.247techblog.com/implement-infinite-scroll-functionality-wordpress-wp-ajax-function/Just need to call a wp ajax function

这篇关于在Ajax加载的内容上进行无限滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 06:37