reactjs - 使用钩子响应一个接一个发生的 CSS 动画
问题描述
我正在尝试制作有 8 张图像的东西,一次显示 4 张。我需要他们在他们进入时有一个动画,在他们退出时有一个动画。单击其中一个时,前 4 个退出。但我只看到进入动画。我假设是因为进入和退出动画同时发生。
有没有办法使用钩子添加延迟或类似的东西,使一个在另一个与 Internet Explorer 兼容的之前发生(超级重要)?代码如下图:
const [question, setQuestion] = React.useState(props.Questions[0]);
const [animate, setAnimate] = React.useState("enter");
React.useEffect(() => {
if (Array.isArray(props.Questions) && props.Questions.length) {
// switch to the next iteration by passing the next data to the <Question component
setAnimate("enter");
setQuestion(props.Questions[0]);
} else {
// if there are no more iterations (this looks dumb but needs to be here and works)
$("#mrForm").submit();
}
});
const onStubClick = (e, QuestionCode, StubName) => {
e.preventDefault();
// store selected stub to be submitted later
var newResponse = response.concat({ QuestionCode, StubName });
setResponse(newResponse);
setAnimate("exit");
// remove the first iteration of stubs that were already shown
props.Questions.splice(0, 1);
if (props.QuestionText.QuestionTextLabel.length > 1) {
// remove first iteration of questiontext if applicable
props.QuestionText.QuestionTextLabel.splice(0, 1);
props.QuestionText.QuestionTextImage.splice(0, 1);
// switch the question text
setQuestionLabel({ Label: props.QuestionText.QuestionTextLabel[0], Image: props.QuestionText.QuestionTextImage[0] });
}
};
解决方案
推荐阅读
- kubernetes - 将 GitLab Runner 安装到 GitLab 项目时出错
- c# - Windows 窗体按钮单击事件仅在完成后将更改应用于窗体
- sql-server - 使用 SSIS 将 csv 文件导入 SQL Server 时,从字符串中删除空格的最有效方法是什么?
- html - 使用 CSS 的过渡动画
- ios - UIRefreshControl:表格视图奇怪地跳跃
- python - 使用具有不同级别的 MultiIndex-ed 列加入/ Marge 的 DataFrame
- html - HTML/CSS:菜单中的子菜单。其中一个按钮应触发与主菜单类似的事件
- c# - c# Language.resx 在我安装编译的应用程序时不起作用
- python - 在 QTableWidget 中禁用多个按钮
- java - 无法解析符号“AppCompatActivity”——没有解决方案