Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2017
    Posts
    16
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Basic Effects Question

    PHP Code:
    var $li = $('li');
    $li.hide().each(function([COLOR="#B22222"]index[/COLOR]) {
    $(
    this).delay(700 * [COLOR="#B22222"]index[/COLOR]).fadeIn(700);

    }); 
    I understand everything except the index . What does the index represent ? What argument it gets when each function it goes through li list.

  2. #2
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    378
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That's an arbitrary, yet in this case descriptive, name for one of the available built in arguments of the each function. When you do any such thing:

    Code:
    $('something').each(function(){whatever;});
    You are iterating over the jQuery object and there are two available built in or automatic arguments. The index of the thing in the collection, and the present thing (element, not a jQuery object). I will often write it:

    Code:
    $('something').each(function(i, el){whatever;});
    The code you posted is skipping the element reference as it appears they (the code writer) don't want/need to use it, and using this index as a multiplier to determine a sort of incremental delay so they don't all fade in at once. The first iteration (0), would have no delay, the second (1) would be 700 ms, the third (2) 1400ms and so on. For more information, see:

    .each() | jQuery API Documentation
    - John


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •