您的位置:首页 > Web前端 > CSS

css3 animation 中的animation-delay效果无效

2016-01-09 17:22 253 查看
在写实例的时候,发现如下方法写的效果总是不显示:

<html>
<head>
<title>animation</title>
</head>
<style type="text/css">

.test{
 margin: 20% 10% 0 10%;
 text-align: center;
 height: 50px;
}
.test>div{
width: 6px;
height: 100%;
background-color: green;
display: inline-block;
-webkit-animation: testAnimation 1.2s infinite ease-in-out;
}

.line2{
-webkit-animation-delay:-1.1s;
}
 .line3{
-webkit-animation-delay:-1.0s;
}
.line4{
-webkit-animation-delay:-0.9s;
}
 .line5{
-webkit-animation-delay:-0.8s;
}

/*定义指定的动画*/
@-webkit-keyframes testAnimation{
/*在执行到某一帧的时候调用指定的动作*/
0%,40%,100%{
-webkit-transform: scaleY(.4);
}
20%{
-webkit-transform: scaleY(1);
}
}

</style>
<body>

<div class="test">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
<div class="line4"></div>
<div class="line5"></div>
</div>

</body>

</html>

调试后发现,改变为如下规则就能够有效果:

<html>
<head>
<title>animation</title>
</head>
<style type="text/css">

.test{
 margin: 20% 10% 0 10%;
 text-align: center;
 height: 50px;
}
.test>div{
width: 6px;
height: 100%;
background-color: green;
display: inline-block;
-webkit-animation: testAnimation 1.2s infinite ease-in-out;
}

.test .line2{
-webkit-animation-delay:-1.1s;
}
.test .line3{
-webkit-animation-delay:-1.0s;
}
.test .line4{
-webkit-animation-delay:-0.9s;
}
.test .line5{
-webkit-animation-delay:-0.8s;
}

/*定义指定的动画*/
@-webkit-keyframes testAnimation{
/*在执行到某一帧的时候调用指定的动作*/
0%,40%,100%{
-webkit-transform: scaleY(.4);
}
20%{
-webkit-transform: scaleY(1);
}
}

</style>
<body>

<div class="test">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
<div class="line4"></div>
<div class="line5"></div>
</div>

</body>

</html>

可以看出,在使用delay的时候,要注意某个元素定义了animation,那么相关的元素如果要想显示效果,那么对应的选择器一定要一致
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: