我在 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');
}
});
最佳答案
试试这个:
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');
} );
关于javascript - 在 click .load() 函数 jquery 上添加预加载器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49932355/