我需要在列表中淡入,然后等待几秒钟,然后重定向到一个新页面。
这是我得到的一个接一个的渐近,这是有效的。如何在此结束时添加延迟,然后重定向?
function fadeLi(elem) {
elem.fadeIn(800, function() {
fadeLi($(this).next().delay(900));
});
}
fadeLi( $('#welcome li:first'));
谢谢你的帮助
不错的递归。这允许您检查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'));