我需要淡入列表,然后等待几秒钟然后重定向到新页面。
这是我为了逐渐消失而产生的。如何在此结尾添加延迟,然后重定向?
function fadeLi(elem) {
elem.fadeIn(800, function() {
fadeLi($(this).next().delay(900));
});
}
fadeLi( $('#welcome li:first'));
感谢您的帮助。
答案 0 :(得分:4)
很好的递归。这允许您检查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'));