定义和用法
animation 属性是一个简写属性,用于设置六个动画属性:
animation-name
animation-duration
animation-timing-function
animation-delay
animation-iteration-count
animation-direction
延迟和循环只需设置delay和animation-iteration-count,可以简写在animation属性里面,也可以单独使用animation-delay和animation-iteration-count设置
例如
div{
animation:mymove 5s infinite
-webkit-animation:mymove 5s infinite /* Safari 和 Chrome */
}
在.high-title h2 样式后面增加:-webkit-animation-delay:6s animation-delay:6s-webkit-animation-fill-mode: forwards animation-fill-mode: forwards opacity: 0完整代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
<html xmlns="
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
body { margin-left: 0pxmargin-top: 0pxmargin-right: 0pxmargin-bottom: 0px}
.high-title h3 { width: 756pxheight: 448pxoverflow: hiddenposition: absolutetop: 20pxleft: 50%margin-left: -328pxz-index: 2opacity: 0-webkit-transition: opacity .5s ease-in-out-moz-transition: opacity .5s ease-in-out-ms-transition: opacity .5s ease-in-outtransition: opacity .5s ease-in-out}
.high-title h3 { opacity: 1-webkit-animation: tmd 1s ease-in-out-moz-animation: tmd 1s ease-in-out-ms-animation: tmd 1s ease-in-outanimation: tmd 1s ease-in-out-moz-animation: tmd 1s ease-in-out-ms-animation: tmd 1s ease-in-out}
.high-title h2 { width: 756pxheight: 448pxoverflow: hiddenposition: absolutetop: 60pxleft: 50%margin-left: -328pxz-index: 2opacity: 0-webkit-transition: opacity .5s ease-in-out-moz-transition: opacity .5s ease-in-out-ms-transition: opacity .5s ease-in-outtransition: opacity .5s ease-in-out}
.high-title h2 { opacity: 1-webkit-animation: tmd 1s ease-in-out-moz-animation: tmd 1s ease-in-out-ms-animation: tmd 1s ease-in-outanimation: tmd 1s ease-in-out-moz-animation: tmd 1s ease-in-out-ms-animation: tmd 1s ease-in-out-webkit-animation-delay:6s animation-delay:6s-webkit-animation-fill-mode: forwards animation-fill-mode: forwards opacity: 0}
@-webkit-keyframes tmd{
0% {
opacity: 0
-webkit-transform: translateX(-20px)
}
100% {
opacity: 1
-webkit-transform: translateX(0)
}
}
@-moz-keyframes tmd {
0% {
opacity: 0
-moz-transform: translateX(-20px)
}
100% {
opacity: 1
-moz-transform: translateX(0)
}
}
@-o-keyframes tmd {
0% {
opacity: 0
-o-transform: translateX(-20px)
}
100% {
opacity: 1
-o-transform: translateX(0)
}
}
@keyframes tmd {
0% {
opacity: 0
transform: translateX(-20px)
}
100% {
opacity: 1
transform: translateX(0)
}
}
</style>
</head>
<body>
<div class="high-title"><h3>第一</h3><h2>第二</h2></div>
</body>
</html>
保留住动画的最后状态2113,在animation后面加上forwards就可5261以了代码如下:4102
-webkit-animation{animations 1s ease 1 forwards}
注意:动画如果只执行一次,1653通过css无法办到,可以把动画结束时的样式写入一个class中,用js在动画结束时把class赋给这个对象。
扩展资料
CSS animation 与 CSS transition 有何区别
一、指代不同
1、animation :属性是一个简写属性,用于设置六个动画属性。
2、transition:属性是一个简写属性,用于设置四个过渡属性。
二、特点不同
1、animation :animation: name duration timing-function delay iteration-count direction,规定需要绑定到选择器的 keyframe 名称。规定完成动画所花费的时间,以秒或毫秒计。
2、transition:transition: property duration timing-function delay,规定设置过渡效果的 CSS 属性的名称。规定完成过渡效果需要多少秒或毫秒。