为什么可以't我重用CSS关键帧动画
Why can't I reuse a CSS keyframe animation?
我想每次提交一个CSS关键帧动画,但目前它只适用于第一次。你能看出我做错了什么吗?
CSS:
@keyframes enlarge {
0% {-webkit-transform: scale(1); -ms-transform: scale(1); transform: scale(1);}
100% {-webkit-transform: scale(1.5); -ms-transform: scale(1.5); transform: scale(1.5);}
}
.enlarge {
animation-name: enlarge;
animation-duration: 2s;
JS:
var enlarge = function(response) {
document.querySelector("#messageContainer").classList.add("enlarge");
var reset = setTimeout(function() {
document.querySelector("#messageContainer").classList.remove("enlarge");
}, 2000);
};
在写这篇文章的时候,我有点期待解决方案会出现,但事实并非如此。
根据您的描述,您的代码似乎可以按预期工作。。。尝试点击下面的"运行代码段":
var enlarge = function(response) {
document.querySelector("#container").classList.remove("hidden");
document.querySelector("#example").classList.add("enlarge");
var reset = setTimeout(function() {
document.querySelector("#example").classList.remove("enlarge");
document.querySelector("#container").classList.add("hidden");
}, 2000);
};
#example {
background: red;
width: 150px;
}
@keyframes enlarge {
0% {-webkit-transform: scale(1); -ms-transform: scale(1); transform: scale(1);}
100% {-webkit-transform: scale(1.5); -ms-transform: scale(1.5); transform: scale(1.5);}
}
.hidden { display: none; }
.enlarge {
animation-name: enlarge;
animation-duration: 2s;
}
<div id="container" class="hidden">
<div id="example">My example text</div>
</div>
<button onclick="enlarge()">Submit</button>
你确定你的放大功能在每次点击提交按钮时都在运行吗?
根据您的enlarge()函数接受一个"response"参数的事实判断,我假设您在AJAX请求的响应处理程序中使用了它——如果表单已经提交过一次,这个AJAX请求会返回一个不成功的错误代码吗?如果这个函数被附加到onSuccess()方法,这将解释为什么它只播放一次动画;只有在第一次点击按钮时,请求才会"成功"。
相关文章:
- 一种读取或更改CSS动画关键帧的方法
- CSS关键帧过渡的最佳方法
- CSS 关键帧动画的随机“起点”
- 使用 JQuery 事件检测特定的 CSS 关键帧动画
- 通过滚动触发 CSS 关键帧动画
- 如何在 css 关键帧中存储内容或元数据
- CSS关键帧——从动态高度开始
- 为什么可以't我重用CSS关键帧动画
- 如何在Javascript中停止和更改CSS关键帧?
- CSS关键帧动画没有移除显示块
- :CSS关键帧元素仅在视口中可见时才设置动画
- 动态改变CSS关键帧值来创建时钟
- 同步css关键帧动画与jQuery setInterval
- jQuery改变方向的CSS关键帧动画中途
- 使用JQuery设置CSS关键帧
- 如何防止css关键帧动画页面加载
- 我可以用JavaScript检测CSS关键帧动画中的百分比
- 有没有一种可行的方法可以使用JS触发CSS关键帧动画
- 如何使 css 关键帧步骤动画响应
- 如何在javascript中使用css关键帧动画