javascript - DOM 元素加载和关闭时的 css 动画

标签 javascript css reactjs animation dom

您好,我正在使用 css 动画属性使元素宽度逐渐增长,并且当元素加载到 DOM 时效果很好

我正在使用的代码:

 @keyframes widthSize {
      0% { width: 0; }
      20% { width: 40px; }
      40% { width: 80px; }
      60% { width: 120px; }
      80% { width: 160px; }
      100% { width: 200px; }
 }

.item-popup-list {
animation: widthSize 200ms ease 0s 1;
}

问题是当元素从 DOM 中移除时,我想让它逐渐缩小, 我可以只使用 CSS 吗,还是我必须使用 jQuery(我的代码是 javascript reactJS)

最佳答案

当元素从 DOM 中移除时,您将无法显示动画。您所能做的就是使用 javascript/jQuery 切换类

关于javascript - DOM 元素加载和关闭时的 css 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50577977/

相关文章:

javascript - 在每次转换时滚动到顶部 react-router-dom v6

javascript - 多次调用同一个服务,是设计不良的迹象吗?

javascript - 从数组中获取唯一值

html - nth-child(odd) 和 nth-child(even) 具有不同的对齐项

html - 将元素居中并向左对齐

javascript - React/Redux - 组件状态未更新

css - 为什么位置: sticky; not work in react?

javascript - 将 java 对象返回给 javascript 时出错

javascript - 一页 Bootstrap 下拉菜单不适用于移动设备

css - 字体系列应用于 iphone 模拟器但未应用于真正的 iphone 设备?