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:
$(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>
Your problem is how you’re calling the galleryScroll() function in your setTimeout. Change that line to this:
The result: http://jsfiddle.net/CYEBC/12/
Note: I’m not sure if this is the desired behavior, but it’s what happens when your code is called properly.