我有一些从包含 html 块的 ajax 调用返回的 html。我想淡出现有块并淡入新块,以便按顺序发生(一次 1 个)。现在它同时发生。
似乎在回调进行时,$.each 函数会不断通过剩余的 html 块,因此它们同时淡入和淡出。有没有办法做到这一点,每个html块在移动到下一个块之前都会淡入淡出?
法典
var $newestResults = $('#newest .pcVideomaincontainer:lt(' + data.d.Newest.ChannelsReturned + ')');
$newestResults.fadeOut('slow'), function () { remove() };
$.each($newestResults, function (index, value) {
$(this).animate({
opacity: 0
}, 1000,
function () {
$(this).remove();
$('#pcContentHolder_newest').prepend(data.d.MostFamous.HtmlChannelSegments[index]).hide().fadeIn('slow');
});
});
根据当前索引添加延迟。
$.each($newestResults, function (index, value) {
$(this).delay(index*1000).animate({
opacity: 0
}, 1000,
function () {
$(this).remove();
$('#pcContentHolder_newest').prepend(data.d.MostFamous.HtmlChannelSegments[index]).hide().fadeIn('slow');
});
});
我还没有测试过它,但是 fadeIn 也应该延迟,因为它在已经延迟的第一个 animate 方法的回调中。
你能在
函数周围使用类似延迟的超时吗?
window.setTimeout(your_function,1000)