[英]How to set animated icons to stop after some time
I have the following code to be displayed following an event: 事件发生后,我将显示以下代码:
$("span[name|='ttimer'").html("<i class='fa fa-refresh fa-spin fa-5x' aria-hidden='true'></i> ");
How would it be possible to let the spinning motion last for example 3 seconds then stop moving? 如何使旋转运动持续例如3秒钟然后停止运动?
Firstly, note your attribute selector is missing the closing ]
. 首先,请注意您的属性选择器缺少结束符
]
。
To do what you require you would need to remove the fa-spin
class on the element. 要执行您需要的操作,您需要删除元素上的
fa-spin
类。 You can do that using setTimeout()
, like this: 您可以使用
setTimeout()
做到这一点,如下所示:
var $span = $("span[name|='ttimer']").html('<i class="fa fa-refresh fa-spin fa-5x" aria-hidden="true"></i>');
setTimeout(function() {
$span.find('.fa-spin').removeClass('fa-spin');
}, 3000);
Maybe you are looking for this, animation-iteration-count
也许您正在寻找这个
animation-iteration-count
div {
animation-iteration-count:3;
-webkit-animation-iteration-count:3; /* Safari and Chrome */
}
this way let you do not have to remove the classname 这样,您不必删除类名
The animation is caused by fa-spin
- you can remove this with a setTimeout: 动画是由
fa-spin
引起的-您可以使用setTimeout将其删除:
setTimeout(function() {
$("span[name|='ttimer']>i.fa-spin").removeClass("fa-spin");
}, 3000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.