How to fade out div slowly, update content, and then fade in div slowly, using jQuery?

前端 未结 6 1570
梦如初夏
梦如初夏 2020-12-10 02:52

I have a div I want to fade out, update its content, and then fade back in. So far I have tried:

$(\'#myDivID\').fadeOut(\'slow\', function() {
         


        
6条回答
  •  盖世英雄少女心
    2020-12-10 03:26

    You should do it this way (this works, is tested code):

    $('#myDivID').fadeOut('slow', function() {
        $('#myDivID').html(content);
        $('#myDivID').fadeIn('slow');
    });
    

    Your code wasn't working because the new created div is instantly visible. Another solution is to add a display:none like the following:

       $('#myDivID').fadeOut('slow', function() {
          $('#myDivID').replaceWith("");
          $('#myDivID').fadeIn('slow');
      });
    

    Hope this helps Cheers

提交回复
热议问题