I have this slideUp function that calls the animate function. The objective is to make a div appear to slide up on the screen by recalling the animate function every 20ms, and rerendering the div in the browser after adjusting the css for the div position. I'm using Node js, and due to the asynchronous behaviour, I believe that the timeout only gets involked once, and that the program continues running while it waits on the timeout to complete. When i print the value of 'bottom' to the console, it has looped through 20 times as expected. Only the final view gets rendered thou. Can anyone offer any way to get around this problem so that it rerenders each of the 20 times?
slideUp: function () {
var bottom=0;
this.animate(bottom);
},
animate: function(bottom){
bottom++;
if (bottom<20){
this.view.getClientNotificationElement().setAttribute("style","margin-bottom:"+bottom+"px");
this.clientNotification.attachTo(this.view.getClientNotificationElement());
setTimeout(this.animate(bottom), 20);
console.log(bottom);
}
}