Javascript 替换后将动画设置为高度0

Javascript 替换后将动画设置为高度0,javascript,jquery,Javascript,Jquery,我正在尝试将动画设置为高度0,然后在执行替换后删除 有人知道为什么jquery动画没有发生吗 $('.dataCard').not('.focused').each(function(){ var div = $('<div />',{ css : { height : $(this).height() } }); $(this).replaceWith(div).animate({ height:0 }, function(){ $(this).re

我正在尝试将动画设置为高度0,然后在执行替换后删除

有人知道为什么jquery动画没有发生吗

$('.dataCard').not('.focused').each(function(){
    var div = $('<div />',{
        css : { height : $(this).height() }
});
    $(this).replaceWith(div).animate({ height:0 }, function(){ $(this).remove() });
$('.dataCard')。不是('.focused')。每个(函数(){
var div=$(''){
css:{height:$(this).height()}
});
$(this.replaceWith(div).animate({height:0},function(){$(this.remove()});
$(this).replaceWith(div);
this
返回到链,在本例中,该链就是您刚刚删除的数据卡元素

$('.dataCard').not('.focused').each(function () {
    var div = $('<div />', {
        css: {
            height: $(this).height()
        }
    });
    $(this).replaceWith(div);
    div.animate({
        height: 0
    }, function () {
        $(this).remove()
    });
});
$('.dataCard')。不是('.focused')。每个(函数(){
var div=$(''){
css:{
高度:$(this).height()
}
});
$(此).替换为(div);
动画师({
身高:0
},函数(){
$(this.remove())
});
});
还要注意,刚插入的元素实际上必须有一个高度才能设置动画。

试试这种方法

var div = null;
$('.dataCard').not('.focused').each(function(){
    var div = $('<div />',{
        css : { height : $(this).height() }
});
if (div != null) {
    $(this).replaceWith(div);
    div.animate({ height:0 }, function(){ $(this).remove() });
}
var div=null;
$('.dataCard')。不是('.focused')。每个(函数(){
var div=$(''){
css:{height:$(this).height()}
});
如果(div!=null){
$(此).替换为(div);
animate({height:0},function(){$(this.remove()});
}

代码不够,请发布html以及更多javascript/jquery代码。请告诉我为什么代码的此实现不起作用?因为出现语法错误,请删除
$(this).height()后面的分号。
->->