Reputation: 2902
Please check the following fiddle: http://jsfiddle.net/tWUVe/
When you click the div
, the p
's get deleted, and I expect that the div
's height will be animted, but no animation happens. How can I achieve an animation with CSS3 only?
Upvotes: 0
Views: 1025
Reputation: 25954
The issue is that there is no opportunity for the transition to occur. What I mean by this is that when elements are removed, they are immediately taken out of the document flow, resizing the parent if needed without a transition.
As a fix for this, you could animate the height of the paragraphs instead (or a similar means)
$('div').click(function() {
var $thisDiv = $(this);
$thisDiv.find('p').css({'height':'0px','margin':'0px'}); // Change p height
// Remove after transition
setTimeout(function() { $thisDiv.find('p').remove(); }, 1000);
});
Upvotes: 1