【问题标题】:Reinitialise JScrollPane after AJAX post loading在 AJAX 加载后重新初始化 JScrollPane
【发布时间】:2014-08-19 19:57:08
【问题描述】:

我在 div #reviewspostscont 中加载帖子,AJAX 代码有效,并且在滚动条到达末尾时加载帖子,但我无法重新初始化 JScrollPane 以显示它们。 我尝试了不同的代码,但没有任何效果,这就是我到目前为止所拥有的。 在此先感谢,马特

jQuery(document).ready(function($) {

$(function()
{
$('#reviewspostscont').each(
    function()
    {


        $(this).jScrollPane(
            {
                horizontalDragMaxWidth : 100
            }
        );
        var api = $(this).data('jsp');
        var throttleTimeout;
        $(window).bind(
            'resize',
            function()
            {
                if (!throttleTimeout) {
                    throttleTimeout = setTimeout(
                        function()
                        {
                            api.reinitialise();
                            throttleTimeout = null;
                        },
                        50
                    );
                }
            }
        );

        $(this).bind(
            'jsp-scroll-x',
            function(event, scrollPositionX, isAtLeft, isAtRight)
            {
            var count = 2;
                if (isAtRight == true) {
        loadArticle(count);
        var api = $(this).data('jsp');
        api.reinitialise();
        count++;
    }


            }
        );

    }
  )




  });


  function loadArticle(pageNumber){    
                $.ajax({
                    url: "<?php bloginfo('wpurl') ?>/wp-admin/admin-ajax.php",
                    type:'POST',
                    data: "action=infinite_scroll&page_no="+ pageNumber + '&loop_file=loop-reviews', 
                    success: function(html){
                        $("#reviewspostscont").append(html);   // This will be the div where our content will be loaded
                    }
                });

            return false;
        }

});

【问题讨论】:

    标签: javascript jquery ajax wordpress jscrollpane


    【解决方案1】:

    您可以使用autoReinitialiseHere's a demo 显示了一个类似的例子。 And another oneAnd another.

    【讨论】:

    • 谢谢,我已经浏览了网站,我无法使用 api.reinitialise... 工作。现在我尝试在 'horizo​​ntalDragMaxWidth : 100' 行下使用 'autoReinitialise:true',但没有任何变化,控制台中也没有错误
    猜你喜欢
    • 1970-01-01
    • 2017-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多