0

I am in trouble to insert incremented value with each function Here is the code

var rfi = 250;
$('.animate_rfi').each(function() {     
    $(this).appear(function() { 
        $(this).delay(rfi).animate({
            opacity : 1,
            right : "0px"
        }, 1500);

    });

    rfi += 50;
}); 

I want to increase value for delay(rfi) in each time each() executes. How can I get this.

2
  • What exactly is the problem with the code you already have? Commented Apr 20, 2014 at 4:10
  • do you receive any errors on console ? Commented Apr 20, 2014 at 4:27

2 Answers 2

1

The each function in jQuery already handles an index over iteration with the first parameter (https://api.jquery.com/each/). I modified your code to handle it. You were not really specific with what you wanted, but the handles an increase of 50 ms at each pass, the first pass being at 250 ms of delay.

var rfi = 250;
$('.animate_rfi').each(function(i) {     
$(this).appear(function() { 
    $(this).delay(rfi + (i * 50)).animate({
        opacity : 1,
        right : "0px"
    }, 1500);

});

//rfi += 50;
}); 
Sign up to request clarification or add additional context in comments.

Comments

0

check your selectors or variable or use .ready() for your code this is working fine for me :

<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>

js :

var num = 0;
$("ul li").each(function(){
num = num+1;
})
alert(num)

http://jsfiddle.net/nE6Q6/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.