javascript - 如何检查我的函数内的所有动画是否已结束?
问题描述
我有这个伪代码。我需要检查所有动画是否已结束。
我的函数里面有很多动画:
function animateText($element, $callback) {
var $this = $element;
var $wordList = $this.text().split("");
$this.text("");
$this.css('opacity', 1);
$.each($wordList, function (idx, elem) {
var newEL = $("<span/>").text(elem).css({
opacity: 0
});
newEL.appendTo($this);
newEL.delay(idx * 125);
newEL.animate({
opacity: 1
}, 500, 'swing', function () {
// now are animations are done
if ($wordList.length === idx + 1) {
$callback();
}
});
});
};
我们开始了!
animateText('#myText', function(){
console.log('ALL ANIMATIONS ARE DONE!');
});
我需要知道所有动画何时结束以及在调用我的回调之后。这种方法有效,但是有可能以某种方式更好地编写它吗?
解决方案
推荐阅读
- c++ - 从只读存储器中读取结构
- python - wxPython;任何文本字段中的右键单击上下文菜单都会导致程序崩溃并出现错误“m_menuDepth > 0”?
- javascript - .3ds 加载器不加载材质和纹理
- python - Python:两个日期时间之间的小时数
- firebase - 尝试获取 SHA 证书指纹时出现 firebase 错误?
- python - 如何将sql输出合并到一个数据框中
- c++ - 即使我通过作用域传递它,我也无法访问我的变量的值
- python - 将有序的dataFrame转换为字典,元素从底部开始
- ios - 如何在 Swift IOS 中使用 NSKeyedArchiver 保存带有子类的对象
- html - 从迭代循环中隐藏特定内容并在隐藏面板中显示