Fade in content
This code hides #title, sets the text, the开发者_JAVA技巧n fades it in.
$('#title').fadeOut(0).text(data.name).fadeIn();
Is there a better way to do the fadeOut(0) part?
If you just want to hide the element instantly, then fade it in with new text, do this:
$('#title').hide().text(data.name).fadeIn();
If instead you want it to animate, your code doesn't wait for anything to happen: it starts to fade in, then sets text instantly, and then fades out (without waiting for anything to finish).
Use callbacks, which are anonymous functions which get called after the parent function has executed completely:
$('#title').fadeOut(function() {
$(this).text(data.name).fadeIn();
});
I really wish jQuery's functions could be chained that easily...
Good luck!
Yes.
$('#title').fadeOut(100, function() {
$(this).text(data.name).fadeIn(100);
});
This version will not change the text until the element has finished animated.
精彩评论