jQuery: FadeOut then SlideUp

前端 未结 6 2104
遥遥无期
遥遥无期 2020-12-04 11:13

If an item is being deleted then I would like to fade it out and slide the other elements up to fill the empty space. Now, when I use fadeOut() the item doesn\'

6条回答
  •  无人及你
    2020-12-04 12:02

    Sounds like it would be better to use the jQuery fadeTo command

     $(function() {
    
         $("#myButton").click(function() {
             $("#myDiv").fadeTo("slow", 0.00, function(){ //fade
                 $(this).slideUp("slow", function() { //slide up
                     $(this).remove(); //then remove from the DOM
                 });
             });
    
         });
    
    });
    

    Working Demo here.

    By performing each command in the callback function of the preceding command, the command will not run until the previous one completes; a "jump" occurs when the element is removed from the DOM without waiting for the slideUp to complete.

提交回复
热议问题