【问题标题】:Ajax Wordpress Pagination with loading gif加载 gif 的 Ajax Wordpress 分页
【发布时间】:2013-09-23 05:58:07
【问题描述】:

我一直在使用这个解决方案:

$(document).ready(function(){
        jQuery(function($) {
            $('.recipe-results').on('click', '#pagination a', function(e){
                e.preventDefault();
                var link = $(this).attr('href');
                $('.recipe-results').animate({opacity:0.1}, 200, function(){
                    $(this).load(link + ' .recipe-results', function() {
                        $(this).animate({opacity: 1},200);
                    });
                });
            });
        });
    });

从这里Simple Wordpress AJAX pagination

并且我希望能够在淡出和淡入时间之间添加加载 gif。我的HTML代码是这样的

  <div class="recipe-results">

  <?php if (have_posts()) : $count=1; ?>
    <div class="clearfix">
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

    <?php $count++; endwhile;?>
    </div>
    <?php endif; ?>

    <div id="pagination" class="clearfix">
          <!-- pagination stuff here -->
    </div> <!-- close pagination -->

    </div> <!-- close recipe-results -->

我尝试了各种解决方案,但我是一个使用 jQuery 的 AJAX 的初学者,所以无法找到可行的解决方案。

提前致谢。

【问题讨论】:

    标签: php jquery ajax wordpress pagination


    【解决方案1】:

    在您的 HTML 中:

    <div id="loading" style="display:none;"> 
      <img src="images/loading.gif" title="loading" />
    </div>
    
    
    $(document).ready(function(){
            jQuery(function($) {
                $('.recipe-results').on('click', '#pagination a', function(e){
                   $('#loading').show();
                    e.preventDefault();
                    var link = $(this).attr('href');
                    $('.recipe-results').animate({opacity:0.1}, 200, function(){
                        $(this).load(link + ' .recipe-results', function() {
                         $('#loading').hide();
                            $(this).animate({opacity: 1},200);
                        });
                    });
                });
            });
        });
    

    默认情况下,loading div 设置为不显示,并且会在 Ajax 请求触发时显示。

    【讨论】:

    • 太棒了,这很有效,但又产生了另一个问题,它只在第一次加载时触发,但我会尝试解决这个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-06
    • 1970-01-01
    • 2017-05-27
    • 2011-05-19
    • 1970-01-01
    相关资源
    最近更新 更多