javascript - 为什么 React 组件上的 CSS 过渡只在一个方向上起作用?
问题描述
我有 4 个 div,我想在按向左或向右箭头键时移动其中一个。这个移动应该是一个过渡而不是瞬时的,但由于某种原因,这个过渡只有在我向左移动时才有效。
我认为这与key
道具或 div 被卸载有关,但在尝试了一堆不同的东西之后,我不再确定了。
请看一下:https ://codesandbox.io/s/confident-grothendieck-oou90?file=/src/App.js
有谁知道发生了什么?
解决方案
在样式中,您只添加了 transition:left 0.3s
. 所以它不适合正确的。您可以将其更改为transition:all 0.3s
.tile {
position: absolute;
display: flex;
justify-content: center;
align-items: center;
width: 50px;
height: 50px;
background-color: lightgrey;
font-size: 32px;
transition: all 0.3s ease;
}
推荐阅读
- docker - 由于设备上没有剩余空间,Docker-compose 失败
- python - 如何在 OSX 上卸载 Anaconda,我尝试了 anaconda-clean 但失败了
- linux - 无法使用 'cp' 使用终端复制文件 libstdc++.so.6.0.21
- awk - awk/sed: post-processing of multi-column fille(s)
- dask - Dask JSONDecodeError
- node.js - 无法使用 sequelize-auto 连接到 SQL Server 来生成模型
- angular - 如何在角度 9 ngIf 条件下的两个字符串之间使用连字符(-)
- python - PyCharm/robotframework-lsp 运行系统解释器而不是 venv
- laravel - 如何解决 Laravel 8 中的 psr-4 错误?
- c# - 尝试从列表中获取元素时出现 System.NotSupportedException