我正在构建一个可以淡入淡出文本数组的东西。
这是我目前的工作:http://jsfiddle.net/9j7U6/
我正在淡入和淡出文本,但当我看到它呈现时,时间已经关闭。
$("#wantPlaceholder").fadeOut().html(wants[i]).fadeIn(2000).delay(3000);
正确的做法是什么?
最佳答案
使用回调。动画完成后将调用回调。以下代码淡出该元素。当它完全淡出时,HTML 会被修改,然后再次淡入。
$("#wantPlaceholder").fadeOut(1000, function(){
$(this).html(wants[i]);
$(this).fadeIn(2000);
});
编辑:好吧,循环可以完成something like this :
(function myLoop(items, index) {
index = (items.hasOwnProperty(index) ? index : 0);
$("#wantPlaceholder").delay(3000).fadeOut(1000, function () {
$(this).html(items[index]);
$(this).fadeIn(1000, function () {
myLoop(items, index + 1);
});
});
}(wants, 0));
关于javascript - jQuery fadeIn() 和 fadeOut() 的正确使用方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21745104/