不知道为什么这不起作用 - Javascript基本增量功能

时间:2014-04-15 22:48:21

标签: javascript

我正在编写代码来增加最基本的进度条......它只是不起作用。 这些是使用的变量:

map.progress_bar = // the progress div that grows inside a container div that is the width of the screen (100%);

progress = 0;

state.window_width = // the width of the window or otherwise $(window).width();

setTimeout(function incProgress(){
        if ( map.progress_bar.width() < state.window_width ) {
            progress += 10;
            map.progress_bar.css({
                width: String(progress + '%')
            });
            console.log('progress: ', map.progress_bar.width());
            console.log('window: ', state.window_width);
            setTimeout(incProgress(), 300);
        }
    }, 300);

请不要让我做setInterval。请向我解释为什么在地球上这不起作用,我感到非常不开心。

1 个答案:

答案 0 :(得分:5)

setTimeout(incProgress(), 300);

调用该函数并将其返回值undefined)传递给setTimeout

您需要将功能传递给setTimeout

删除()

相关问题