3

我需要淡入列表,然后等待几秒钟,然后重定向到新页面。

这是我一个接一个地淡入淡出所得到的,这很有效。如何在此结束时添加延迟,然后重定向?

    function fadeLi(elem) {
        elem.fadeIn(800, function() {
            fadeLi($(this).next().delay(900));
        });

    }

    fadeLi( $('#welcome li:first'));

谢谢您的帮助。

4

1 回答 1

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'));
于 2012-12-22T01:39:02.307 回答