0

I recently used a nice little jquery script that loads images with a given class sequentially and fades them in one by one as a page loads.

The Jquery

$(function() {
$(".faded").hide()    
$(".faded").each(function(i) {
    $(this).delay(i * 100).fadeIn(500);
});
});

Example HTML

<div class="faded"><img class="someclass" src="images/example1.jpg" /></div>
<div class="faded"><img class="someclass" src="images/example1.jpg" /></div>
<div class="faded"><img class="someclass" src="images/example1.jpg" /></div>
<div class="faded"><img class="someclass" src="images/example1.jpg" /></div>
.....

An example of this in action can be viewed here http://comill.com/animation/

This got me thinking that it would be quite nice to create a rollover or hover script that loads images in a similar way.

For example, in the demo link given above only the green disc would be visible on the page and when a user hovers over this disc the petals would fade in one by one. Ideally the petals would then all fade out at once on mouseout.

I have spent a while researching this and feel that it should be fairly simple to achieve, however so far I have not found a solution while searching through Google so if anyone can provide a solution any help would be greatly appreciated.

1 Answer 1

2

use a .hover() on the green disk element

for your example, give the following code a spin

$(document).ready(function(){
    var faded = $(".faded");
    faded.hide();
    $('#midbut').hover(function(){
        // mouseenter
        faded.each(function(i) {
            $(this).delay(i * 100).fadeIn(500);
        });
    }, function(){
        // mouseleave
        faded.fadeOut(500);
    });
});

also u shouldn't be hiding the elements with jquery if you can do it with css on the page init

Sign up to request clarification or add additional context in comments.

2 Comments

That's perfect! Really appreciate that, also thanks for the pointer re hiding images with jquery. I was aware of this and had originally used CSS, I can't remember exactly why I used hide in the script instead but there was reasoning behind it at the time I originally used it. Thanks again.
glad it help you. you can accept the answer by ticking the tick icon

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.