css动画其他div,删除另一个div时的CSS3 Transition动画

如果您的div具有相似的高度,则可以这样做。

关键是为列表中第一项的边距高度设置动画。

.test {

left: 0px;

top: 0px;

width: 400px;

height: 300px;

position: relative;

}

.notification {

height: 40px;

background: lightblue;

margin: 2px;

}

.notification:first-child {

-webkit-animation: move 1s ease-out;

animation: move 1s ease-out;

}

@-webkit-keyframes move {

0% {margin-top: 42px;}

100% {margin-top: 2px;}

}

@keyframes move {

0% {margin-top: 42px;}

100% {margin-top: 2px;}

}

在演示中有一点缺点,就是第一次渲染时,动画也会播放。在制作中,这可能不是一个问题,因为列表在开头就是空的。

解决上一个问题的更好解决方案:

CSS

.notifications {

left: 0px;

top: 0px;

width: 400px;

height: 300px;

position: relative;

border: solid 1px green;

padding-top: 40px;

transition: padding-top 1s;

}

.notifications:empty {

padding-top: 0px;

}

.notification {

height: 40px;

background: lightblue;

margin: 2px;

transition: margin-top 1s;

}

.notification:first-child {

margin-top: -38px;

}

我注意到我正在使用动画,但这种过渡就足够了。除了主要问题:当我向空容器添加元素时避免转换。解决这个问题的方法是在容器元素中创建相反的过渡。通过CSS查看属性集到.notifications:empty。

这有点尴尬,因为填充不会支持负值;这意味着与自然相反,并改变通知方面的边缘。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值