Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css3 sequential animation for parent and child elements

How can I make the animation of a child element to occur after the parent has done its animation, i.e. the parent div fades in then its child element fades in 1 second later?

I have tried many tricks but nothing works, the child element is still fading at the same time as the parent.

Please see here: http://jsfiddle.net/oeLbh43o/

HTML:

<div class="parent">
    <h1>The Title Here</h1>
</div>

CSS:

.parent {
    width: 250px;
    height: 250px;
    background: #fff;
    border: 1px solid #000;
    -webkit-box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    -moz-box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    padding: 10px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    -webkit-transition: all 0.5s ease-in-out;
    -moz-transition: all 0.5s ease-in-out;
    transition: all 0.5s ease-in-out;
}

.parent h1 {
    -webkit-transition: all 0.9s ease-in-out;
    -moz-transition: all 0.9s ease-in-out;
    transition: all 0.9s ease-in-out;
    opacity: 0;
}

.parent:hover {
    width: 300px;
    height: 300px;
}
.parent:hover h1 {
    opacity: 1;
    -webkit-animation-delay: 5s;
    -moz-animation-delay: 5s;
    animation-delay: 5s;
}

Many Thanks

like image 599
Shaoz Avatar asked Jan 23 '26 11:01

Shaoz


1 Answers

You are using CSS transitions so you should indicate transition-delay instead of animation-delay.

.parent {
    width: 250px;
    height: 250px;
    background: #fff;
    border: 1px solid #000;
    -webkit-box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    -moz-box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    padding: 10px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    -webkit-transition: all 0.5s ease-in-out;
    -moz-transition: all 0.5s ease-in-out;
    transition: all 0.5s ease-in-out;
    -webkit-transition-delay: 2s;
    -moz-transition-delay: 2s;
    transition-delay: 2s;
}

.parent h1 {
    -webkit-transition: all 0.9s ease-in-out;
    -moz-transition: all 0.9s ease-in-out;
    transition: all 0.9s ease-in-out;
    opacity: 0;
    -webkit-transition-delay: 0;
    -moz-transition-delay: 0;
    transition-delay: 0;
}

.parent:hover {
    width: 300px;
    height: 300px;
    -webkit-transition-delay: 0;
    -moz-transition-delay: 0;
    transition-delay: 0;
}
.parent:hover h1 {
    opacity: 1;
    -webkit-transition-delay: 2s;
    -moz-transition-delay: 2s;
    transition-delay: 2s;
}
<div class="parent">
    <h1>The Title Here</h1>
</div>
like image 154
MatthewG Avatar answered Jan 26 '26 03:01

MatthewG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!