1

I have a wall of images and underneath some text, with that i would like the image to fade in then its text to fade in.
With this code below, each image fades in then ALL of the text fades in at once.

Q: how can i use index so that the corresponding text will fade in following its image?
I've found a similar question but could'nt get this to work.

css:
.mydiv a, .mydiv p{ display:none;}

js:

$('.mydiv a').each(function(index){
    var c = $(this);
    $(new Image()).load(function(){
            c.fadeIn(500);
            setTimeout(function(){ $('.mydiv p').fadeIn(250); }, 500);// where would i place index
    }).attr('src', c.find('img').attr('src'));
});

2 Answers 2

4

Navigate from the existing c variable if there is one mydiv for each p element

$(c).closest(".mydiv").find("p").fadeIn(250);

or use .eq()

$(".mydiv p").eq(i).fadeIn(250);
Sign up to request clarification or add additional context in comments.

Comments

0
$('.mydiv a').each(function(i, e){
    var c = $(this);
    e.load(function(){
            c.fadeIn(500);
            setTimeout(function(){ $('.mydiv p').fadeIn(250); }, 500);// where would i place index
    }).attr('src', c.find('img').attr('src'));
});

1 Comment

anchor tags don't natively trigger a load event, and load event's don't bubble in all browsers.

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.