Islamic mind

november 23, 2010

Javascript setInterval

Filed under: Programming — majestrooo @ 5:26 f m

If you’re creating an animation with Javascript, then you most likely will have to use the setInterval method. This method accepts a function/expression and an interval saying how often that function/expressions should be evaluated.

I was trying this out to get a nice sliding animation with a call like this:

setInterval( openSlideBox(bars[i]), 30 )

I’m not gonna explain openSlideBox but it’s only simple logic for checking current height of the slided box, when to stop etc. In this post I wanted to tell about the problem of the function openSlideBox only getting called once when using setInterval. I had specified it to be called every 30ms, why was it only being called once??

If you’re having this problem too, you need to add ”function() { call-to-function }” as the first parameter. I have not looked into this further, but I believe it has to do with how the parameter is evaluated. I guess I could google it, but it’s more fun with interaction and if someone can share his/her knowledge in the comments it would more fun…for all of us :).

Good luck!


Kommentera »

Inga kommentarer ännu.

RSS feed for comments on this post. TrackBack URI


Fyll i dina uppgifter nedan eller klicka på en ikon för att logga in: Logo

Du kommenterar med ditt Logga ut /  Ändra )


Du kommenterar med ditt Google+-konto. Logga ut /  Ändra )


Du kommenterar med ditt Twitter-konto. Logga ut /  Ändra )


Du kommenterar med ditt Facebook-konto. Logga ut /  Ändra )


Ansluter till %s

Blogga med

%d bloggare gillar detta: