【问题标题】:Adding a pre-loader on click .load() function jquery在单击 .load() 函数 jquery 上添加预加载器
【发布时间】:2018-09-30 14:56:58
【问题描述】:

我在 jquery 中使用 .load() 时遇到问题

这是我当前的代码

jQuery(document).on('click','#Pagination a', function(e){
    e.preventDefault();
    var link = jQuery(this).attr('href');
    var nxtPage =  jQuery(this).attr('href');
    window.history.pushState('obj', 'newtitle', nxtPage);
    jQuery('.preloadswitch').load(link+' .the-categories').fadeIn('slow');      
});

这确实有效,但是我需要它在获取内容时淡入 + 预加载器,然后在内容可见时消失

我可以把它做成一个具有“beforeSend”或“success”功能的ajax吗?谢谢

这也不行

jQuery('.preloadswitch').load(link+'.the-categories',function(response,status,xhr){
    if(status == 'sucess'){ 
        jQuery('.preloadswitch').removeClass('addpreloader');
    }
});

【问题讨论】:

    标签: javascript jquery wordpress pagination


    【解决方案1】:

    试试这个:

    jQuery('.preloadswitch')
        .fadeIn('slow')                // Fades it in.
        .addClass('addpreloader')      // Adds the pre-loader class.
        // Loads the content.
        .load(link+' .the-categories', function(){
            // Removes the pre-loader class once AJAX is completed.
            $(this).removeClass('addpreloader');
        } );
    

    【讨论】:

    • 嗨 Sally CJ,它触发和错误 (TypeError: jQuery(...).fadeIn(...).addClass(...).load(...).always 不是一个函数)
    • 很抱歉。请使用更新后的代码重试。
    • 嗨@Sally CJ,它现在可以工作了,非常感谢你,你的救命稻草:-)
    • 很高兴它对您有所帮助,祝您一切顺利。 =)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多