Simple nested setTimeout() only runs once (JavaScript)

Posted by danielfaraday on Stack Overflow See other posts from Stack Overflow or by danielfaraday
Published on 2012-04-06T17:09:26Z Indexed on 2012/04/06 17:29 UTC
Read the original article Hit count: 144

Filed under:
|
|

For some reason my galleryScroll() function only runs once, even though the function calls itself using setTimeout(). I'm thinking the issue may be related to scope, but I'm not sure:

http://jsfiddle.net/CYEBC/2/

$(document).ready(function() {
    var x = $('#box').offset().left;
    var y = $('#box').offset().top;
    galleryScroll();

    function galleryScroll() {
        x = x + 1;
        y = y + 1;
        $('#box').offset({
            left: x,
            top: y
        });
        setTimeout('galleryScroll()', 100);
    }
});?

The HTML:

<html>
<head>
</head>
<body>
    <div id="box">
    </div>
</body>
</html>?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about nested