开发者

.load() image loading gif

I am loading content dynamically using .load() i want to display a loading image (.gif) to show the user that something is happening.

How would i achieve this with the below code?

$('#prac_slider li a').click(function(){
    if($(this).attr('class') != 'active') {
        $('#prac_slider li a').removeClass('active').animate({ "opacity" : 0.5 });
        $(this).addClass('active').animate({ "opacity" : 1 });
        var $permalink = $(this).attr('href');
        $('#practitioner').fadeOut(1000, function(){
            $(this).load($permalink + ' #pracLoad',function(){
            $(this).fadeIn开发者_StackOverflow中文版();
        })
        });
    }
    return false;
});


You might just want to do something like

$(document).ajaxStart(function(){ 
    $('#AJAXload').show(); 
}).ajaxStop(function(){ 
    $('#AJAXload').hide();
});


add a style to your css file

.hidden {display:none;}

and now use in your jquery code as follows

$('#prac_slider li a').click(function(){
    if($(this).attr('class') != 'active') {
        $('#loadingimage').removeClass('hidden');
        $('#prac_slider li a').removeClass('active').animate({ "opacity" : 0.5 });
        $(this).addClass('active').animate({ "opacity" : 1 });
        var $permalink = $(this).attr('href');
        $('#practitioner').fadeOut(1000, function(){
            $(this).load($permalink + ' #pracLoad',function(){
            $(this).fadeIn();
        })
        $('#loadingimage').addClass('hidden');
        });
    }
    return false;
});

and finally have a image like this

<img src=""images/loading.gif" class="hidden" id="loadingimage" />


$.ajax({
    beforeSend: function(){
// Handle the beforeSend event
    $('#loading').show();
},
    complete: function(){
    // Handle the complete event
    $('#loading').hide();
    }
    //DO STUFF
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜