gpt4 book ai didi

html - 父子元素的css3顺序动画

转载 作者:可可西里 更新时间:2023-11-01 13:08:40 27 4
gpt4 key购买 nike

如何让子元素的动画在父元素完成其动画后发生,即父 div 淡入然后其子元素在 1 秒后淡出?

我尝试了很多技巧,但没有任何效果,子元素仍然与父元素同时淡出。

请看这里: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;
}

非常感谢

最佳答案

您正在使用 CSS 过渡,因此您应该指明 transition-delay 而不是 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>

关于html - 父子元素的css3顺序动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28280273/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com