I am trying to understand this jquery code, I understand everything: modulo, loop, etc., except that "i" means in .each (function (i). I tried searching, but this code does not return good search results Does it represent every img that has the identifier #photos? If it is not like the variable currentPhoto. Any help with understanding this or linking to useful information would be greatly appreciated.
function rotatePics(currentPhoto) { //number is index of current photo var numberOfPhotos = $('#photos img').length; currentPhoto = currentPhoto % numberOfPhotos; $('#photos img').eq(currentPhoto).fadeOut(function() { // re-order the z-index $('#photos img').each(function(i) { $(this).css( 'zIndex', ((numberOfPhotos - i) + currentPhoto) % numberOfPhotos ); }); $(this).show(); setTimeout(function() {rotatePics(++currentPhoto);}, 4000); }); }
Thanks in advance!
Edit: In case someone goes through jquery: a newcomer to the ninja book has the same doubts: (i) is based on 0 and currentPhoto is on 1, so for example, the 1st img element will look like this (when provided that only 6 photos):
((6 - 0) + 1 % 6 ((numberOfPhotos - i) + currentPhoto) % numberOfPhotos
always adding 1 ensures that the remainder is always 1, so make sure the z-index is always 1.
Thanks for helping all the people!
source share