This is what I tried to do
for ( i=1; i<=1000; i+=100) {
setInterval(someFunction, i);
}
What I want to achieve is that when page loads the box will appear and its shadow will twinkle slow and then fast and will stop at when i=1000.
I am newbie and so far, I did this.
Is it possible or not?
Yes. Assuming
someFunctionis either a reference to a function or a string containing JavaScript code your for loop will “work” as is, where by “work” I mean “not give syntax errors but almost certainly not achieve what I imagine you really want to do”.The
setInterval()function calls the function you pass it repeatedly, with a fixed (subject to browser quirks) delay between each call. It keeps calling the function for as long as the page is open or until you useclearInterval()to cancel it.So by calling
setInterval()in a loop you are setting up (in your case) ten independent intervals all of which call your function repeatedly. The first callssomeFunctionat a 0ms interval, which is smaller than the browser will actually use so will be rounded up to more like 4ms. The second interval will callsomeFunctionat a 100ms interval. The third calls the function at a 200ms interval. And so on. After your loop finishes your function will be repeatedly called more times per second than I can be bothered to calculate.It seems likely that what you really wanted to do is call
someFunction()exactly 10 times with a 100ms delay between each call. If that is the case you could instead use thesetTimeout()function within your loop, because (each use of)setTimeout()will call your function exactly once after the specified delay.