Content Attenuation

This code hides #title, sets the text, then disappears.

$('#title').fadeOut(0).text(data.name).fadeIn();

Is there a better way to make the fadeOut (0) part?

+3
source share
2 answers

If you just want to hide the element instantly, then extinguish it with new text, do the following:

$('#title').hide().text(data.name).fadeIn();

If instead you want it to be animated, your code did not wait for something to happen: it starts to disappear, then it instantly sets the text and then disappears (without waiting for the completion of something).

Use callbacks, which are anonymous functions that are called after the full implementation of the parent function:

$('#title').fadeOut(function() {
  $(this).text(data.name).fadeIn();
});

I really want jQuery functions to be able to be constrained so easily ...

Good luck

+3
source

Yes.

$('#title').fadeOut(100, function() {

    $(this).text(data.name).fadeIn(100);     

});

, .

+3

Source: https://habr.com/ru/post/1787377/


All Articles