I have jquery function that is triggered by a ‘click’ handler:
$('#showDatesCheckbox').click(function(){
var table = $('#planningViewTable').find('tr');
if ($('#showDatesCheckbox').is(':checked')) {
table.find('.textDate').stop().animate({
"opacity": 1
}, 1000);
table.find('.inlineTextDate').stop().animate({
"opacity": 1
}, 1000);
}
else {
table.find('.textDate').stop().animate({
"opacity": 0
}, 1000);
table.find('.inlineTextDate').stop().animate({
"opacity": 0
}, 1000);
}
});
I wanted to have an ajax loading indicator animation, so I need it to show when the click is triggered, and hide when the operation is completed, so I figure callback but it doesn’t seem to be working when I set it up as follows:
$('#showDatesCheckbox').click(function(){
$('#planningView').mask('Loading...');
var table = $('#planningViewTable').find('tr');
if ($('#showDatesCheckbox').is(':checked')) {
table.find('.textDate').stop().animate({
"opacity": 1
}, 1000);
table.find('.inlineTextDate').stop().animate({
"opacity": 1
}, 1000);
}
else {
table.find('.textDate').stop().animate({
"opacity": 0
}, 1000);
table.find('.inlineTextDate').stop().animate({
"opacity": 0
}, 1000);
}
},
$('#planningView').unmask();
);
The
clickevent is triggered immediately, and has a duration of 0, thus it doesn’t have any callback.But what you’re using,
animate, does have a duration, so it has a callback. Your callback function should then be inside the.animate:But you’re using multiple animates, so i guess you want your callback function to be called when all these animates are finished “animating”. Here’s what i would do :
There is one more thing you should know : calling
.animateto change opacity is great, but if you only change opacity, there is a method that does only that, and also has a callback :fadeIn()andfadeOut().