typecho无限流加载更多

/* 加载更多文章 */
var isLoading = false;

$(window).on('scroll touchmove', function() {
    var A = Math.floor($(window).scrollTop()) + window.innerHeight;
    var B = $(document).height();
    if (!isLoading && Math.abs(A - B) < 50 && $('.archive_next a.next').length > 0) {
        isLoading = true;
        loadMoreArticles();
    }
});

function loadMoreArticles() {
    var $next = $('.archive_next a.next');
    var href = $next.attr('href');

    if (href) {
        $next.addClass('loading').text('loading...');

        // 这里您可以选择使用 Pjax 或直接 AJAX
        // 使用 Pjax(如果后端支持 Pjax)
        // pjax.loadUrl(href);

        // 或者,使用普通的 AJAX(这里假设您不想或不能使用 Pjax)
        $.ajax({
            url: href,
            type: 'get',
            success: function(data) {
                // 假设数据是一个完整的 HTML 片段,并且我们只需要提取其中的部分
                var $res = $(data).find('.post');
                $('#content').append($res.fadeIn(500));

                // 更新“加载更多”链接(如果存在)
                var $newNext = $(data).find('.archive_next a.next');
                if ($newNext.length) {
                    $('.archive_next').empty().append($newNext);
                } else {
                    $('.archive_next').empty().append('<span class="text-xs over text-gray-950 ">—— 我也是有底线的 ——</span>');
                }

                $next.removeClass('loading').text('more');
                isLoading = false;
            },
            error: function(xhr, status, error) {
                console.error('加载失败:', error);
                $next.removeClass('loading').text('加载失败');
                isLoading = false;
            }
        });
    }
}

index.php里添加

<div class="bg-white links text-xs archive_next" style="padding: 30px 0;text-align: center">
<?php $this->pageLink('查看更多','next'); ?>
</div> 

请使用#content包裹着post 如下图

更新一下

加载出来的a链接导致pjax失效只要把链接改成

比如

修改前

<a href="<?php $this->permalink() ?>"><?php echo get_Abstract($this,140); ?></a>

修改后

<span onclick="pjax.loadUrl('<?php $this->permalink() ?>');"><?php echo get_Abstract($this,140); ?></span>

偶遇你博客icon-default.png?t=N7T8https://ouyu.me/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值