Insert HTML string on page with fade in

3

$("body").append('<div class="shadow-full"></div>');

But it appears at once, wanted to have an effect for it to appear more smoothly, can you do that?

    
asked by anonymous 18.12.2016 / 20:09

1 answer

3

You have to separate this in steps.

  • converts this HTML string to an element
  • Hide it
  • inserts it into the DOM
  • fade in

To do this "there jQuery" might look like this:

$('<div class="shadow-full">Teste!</div>')
  .hide()
  .appendTo("body")
  .fadeIn(1000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
18.12.2016 / 20:26