这个动画效果可以拆分三步:
- 字是先去到右下,再去到左上,再回位置上的,可以使用
transform
的translate
- 字有旋转,可以用
transform
的relate
- 字从模糊到渐渐清晰,可以使用
opacity
完整代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CSS Text animation Right Down Flip top Left</title>
<style>
.container {
margin: 0;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
font-size: 50px;
/*color: #24a8e6;*/
color: #ddb40f;
font-weight: bold;
}
.left-flip span{
/*行内块级才能 transform 属性*/
display: inline-block;
animation: revolveScale .3s forwards;
opacity: 0;
}
@keyframes revolveScale {
0% {
transform: translate(0) rotate(0deg) scale(1);
opacity: 0;
}
30% {
transform: translate(30px, 50px) rotate(360deg) scale(1);
}
60% {
transform: translate(-80px, -100px) rotate(180deg) scale(1);
}
100% {
transform: translate(0) rotate(0deg) scale(1);
opacity: 1;
}
}
.left-flip span:nth-of-type(2) {
animation-delay: .1s;
}
.left-flip span:nth-of-type(3) {
animation-delay: .2s;
}
.left-flip span:nth-of-type(4) {
animation-delay: .3s;
}
.left-flip span:nth-of-type(5) {
animation-delay: .4s;
}
.left-flip span:nth-of-type(6) {
animation-delay: .45s;
}
.left-flip span:nth-of-type(7) {
animation-delay: .5s;
}
.left-flip span:nth-of-type(8) {
animation-delay: .55s;
}
.left-flip span:nth-of-type(9) {
animation-delay: .6s;
}
.left-flip span:nth-of-type(10) {
animation-delay: .65s;
}
.left-flip span:nth-of-type(11) {
animation-delay: .7s;
}
/*按钮样式*/
.repeat {
padding: 5px;
font-size: 12px;
text-decoration: none;
color: rebeccapurple;
border: 1px solid #24a8e6;
}
</style>
</head>
<body>
<div class="container left-flip" >
<span>H</span>
<span>e</span>
<span>l</span>
<span>l</span>
<span>o</span>
<span>W</span>
<span>o</span>
<span>r</span>
<span>l</span>
<span>d</span>
<span>!</span>
<a class="repeat" href="javascript:void(0);">Repeat Animation</a>
</div>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script>
<script>
$('.repeat').click(function () {
var $container = $('.container')
$container.removeClass('left-flip')
setTimeout(function () {
$container.addClass('left-flip')
}, 20)
})
</script>
</body>
</html>