2009-11-27 5 views

답변

298
$target.hide('slow'); 

또는

$target.hide('slow', function(){ $target.remove(); }); 

다음, 애니메이션을 실행 DOM

에서 제거 당신은

$target.hide('slow') 

처럼

+6

.remove() 메소드 매우 특히 DOM에서 노드를 제거합니다. .hide() 메소드는 표시 속성이 표시되지 않지만 여전히 존재한다는 표시 속성 만 변경합니다. – micahwittman

+5

$ (this) .remove()가 더 잘 작동합니다. – Envil

+1

@ Envil 포스터는 천천히 그것을 제거하는 방법을 물었다. .remove()는 즉시 실행합니다. – pixelearth

-3

을 의미?

+0

예, 애니메이션 후에도 삭제해야합니다. – Mask

12

요소를 숨긴 다음 제거해야하는 경우 hide 메서드의 콜백 함수에서 remove 메서드를 사용합니다.

이 당신은 remove 메소드를 호출하기 전에 애니메이션을 사용할 필요가

$target.hide("slow", function(){ $(this).remove(); }) 
+0

+1은 위의 의견대로 답변을 얻었 기 때문에 +1했습니다. 어떻게 든'$ target '을 반복하는 대신'$ (this)'를 좋아한다. – goodeye

14
$('#ur_id').slideUp("slow", function() { $('#ur_id').remove();}); 
0

, 그것은 작동합니다

을 참조하십시오. 여기에 있습니다 :

1

모든 답변이 좋았지 만 모든 전문가가 "폴란드어"가 부족하다는 것을 알았습니다.

$target.fadeTo(1000, 0.01, function(){ 
    $(this).slideUp(150, function() { 
     $(this).remove(); 
    }); 
}); 
0

내가 늦게 파티에 작은 해요,하지만 Google 검색에서 와서 정답을 찾지 못한 나 같은 사람을 위해 : 나는, 페이드 아웃까지 슬라이딩 후 제거이 함께했다 . 이 좋은 해답이 여기 있습니다,하지만 난 속히, 찾고 있던 정확히 무엇을 오해하지 마세요, 여기에 내가 무슨 짓을 :

$(document).ready(function() { 
 
    
 
    var $deleteButton = $('.deleteItem'); 
 

 
    $deleteButton.on('click', function(event) { 
 
     event.preventDefault(); 
 

 
     var $button = $(this); 
 

 
     if(confirm('Are you sure about this ?')) { 
 

 
     var $item = $button.closest('tr.item'); 
 

 
     $item.addClass('removed-item') 
 
     
 
      .one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function(e) { 
 
      
 
       $(this).remove(); 
 
     }); 
 
     } 
 
     
 
    }); 
 
    
 
});
/** 
 
* Credit to Sara Soueidan 
 
* @link https://github.com/SaraSoueidan/creative-list-effects/blob/master/css/styles-4.css 
 
*/ 
 

 
.removed-item { 
 
    -webkit-animation: removed-item-animation .6s cubic-bezier(.55,-0.04,.91,.94) forwards; 
 
    -o-animation: removed-item-animation .6s cubic-bezier(.55,-0.04,.91,.94) forwards; 
 
    animation: removed-item-animation .6s cubic-bezier(.55,-0.04,.91,.94) forwards 
 
} 
 

 
@keyframes removed-item-animation { 
 
    from { 
 
     opacity: 1; 
 
     -webkit-transform: scale(1); 
 
     -ms-transform: scale(1); 
 
     -o-transform: scale(1); 
 
     transform: scale(1) 
 
    } 
 

 
    to { 
 
     -webkit-transform: scale(0); 
 
     -ms-transform: scale(0); 
 
     -o-transform: scale(0); 
 
     transform: scale(0); 
 
     opacity: 0 
 
    } 
 
} 
 

 
@-webkit-keyframes removed-item-animation { 
 
    from { 
 
     opacity: 1; 
 
     -webkit-transform: scale(1); 
 
     transform: scale(1) 
 
    } 
 

 
    to { 
 
     -webkit-transform: scale(0); 
 
     transform: scale(0); 
 
     opacity: 0 
 
    } 
 
} 
 

 
@-o-keyframes removed-item-animation { 
 
    from { 
 
     opacity: 1; 
 
     -o-transform: scale(1); 
 
     transform: scale(1) 
 
    } 
 

 
    to { 
 
     -o-transform: scale(0); 
 
     transform: scale(0); 
 
     opacity: 0 
 
    } 
 
}
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
    <meta charset="utf-8"> 
 
    <meta name="viewport" content="width=device-width"> 
 
    <title>JS Bin</title> 
 
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/> 
 
</head> 
 
<body> 
 
    
 
    <table class="table table-striped table-bordered table-hover"> 
 
    <thead> 
 
     <tr> 
 
     <th>id</th> 
 
     <th>firstname</th> 
 
     <th>lastname</th> 
 
     <th>@twitter</th> 
 
     <th>action</th> 
 
     </tr> 
 
    </thead> 
 
    <tbody> 
 
     
 
     <tr class="item"> 
 
     <td>1</td> 
 
     <td>Nour-Eddine</td> 
 
     <td>ECH-CHEBABY</td> 
 
     <th>@__chebaby</th> 
 
     <td><button class="btn btn-danger deleteItem">Delete</button></td> 
 
     </tr> 
 
     
 
     <tr class="item"> 
 
     <td>2</td> 
 
     <td>John</td> 
 
     <td>Doe</td> 
 
     <th>@johndoe</th> 
 
     <td><button class="btn btn-danger deleteItem">Delete</button></td> 
 
     </tr> 
 
     
 
     <tr class="item"> 
 
     <td>3</td> 
 
     <td>Jane</td> 
 
     <td>Doe</td> 
 
     <th>@janedoe</th> 
 
     <td><button class="btn btn-danger deleteItem">Delete</button></td> 
 
     </tr> 
 
    </tbody> 
 
    </table> 
 
    
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 

 
</body> 
 
</html>

관련 문제