不错的递归。这允许您检查 jQuery 对象的长度以检测您是否已用尽列表项。
function fadeLi(elem) {
// elem is a jQuery object which support length property
if (elem.length === 0){
// we are out of elements so we can set the location change
setTimeout(function(){
// set the window location to whatever url you like
window.location = 'https://www.where.ever/you/are/taking/the/user';
// adjust the timeout in milliseconds
}, 900);
// in this case you no longer want to recursively call so return
return;
}
elem.fadeIn(800, function() {
// note: I don't think delay call has any impact here.
fadeLi($(this).next().delay(900));
});
}
fadeLi( $('#welcome li:first'));