Consider the following block of code
var interval = setTimeout(function()
{
var left = parseInt(self.element.style.left) - 10;
var width = parseInt(self.element.style.width) + 10;
if(width <= self.width)
{
self.element.style.left = left + "px";
self.element.style.width = width + "px";
setTimeout(increaseWidthLeft(self), 10);
}
else
{
window.clearInterval(interval);
}
}, 5);
And this one:
var interval = setTimeout(function()
{
var left = parseInt(self.element.style.left) - 10;
var width = parseInt(self.element.style.width) + 10;
if(width <= self.width)
{
self.element.style.left = left + "px";
self.element.style.width = width + "px";
setTimeout(function(){increaseWidthLeft(self);}, 10);
}
else
{
window.clearInterval(interval);
}
}, 5);
They are almost the same right? But when i'm running the first version the "animation" is running with stunning speed... however the second one is running almost 3 times slower than the first one. What is going on here? Any help is very appreciated