In a JS function using setIntervall, I want to perform a jquery animation every 10 loops (in the other 9 loops, other animations are being displayed).
I am using the variable i in my function and it increments +1 each loop. Is there a very easy way to check in javascript if i is a multiple of 10 (in order to perform my jquery animation)?
In PHP I would simply do if(($i % 10) ==开发者_开发技巧 0)
... but I didn't find it in JS.
Did you try it? I found a few sites that claim that the same operator %
will work in JavaScript.
The modulus operator in JS works just fine.
for (var ii=0; ii < 100; ii++)
{
if (ii%10 == 0) console.log(ii);
}
It still works in JS:
i = x % 10;
Here's a list of other operators:
http://www.w3schools.com/js/js_operators.asp
精彩评论