纯css动画效果--animate的应用

前言

需要某个小图标或者文字转圈的效果,部分伙伴会用js去写一个定时器,然后再去清空定时器,这样做是比较麻烦的。之前在学css里的有一个animate方法。下面就讲animate的使用:

animate调用的属性值

语法:animation: name duration timing-function delay iteration-count direction;

1.animation-name 规定需要绑定到选择器的 keyframe 名称。
2.animation-duration 规定完成动画所花费的时间,以秒或毫秒计(必须填写,否则为0动画将失效)。
3.animation-timing-function 规定动画的速度曲线(默认:ea se)。
4.animation-delay 规定在动画开始之前的延迟。
5.animation-iteration-count 规定动画应该播放的次数(linear:均速运的,infinite循环运动)。
6.animation-direction 规定是否应该轮流反向播放动画(反向:alternate 默认:normal)。

@keyframes 的使用(必须与animate结合)

语法:@keyframes animationname {keyframes-selector {css-styles;}}

animationname 定义的animation的名称必须写
keyframes-selector 动画持续时间的百分比。合法值:1-100% from(0%) to(100%)
css-styles 必须的,一个或者多个合法的css动画

实列



div{
width:100px;
height:100px;
background:palegreen;
position:relative;
animation:mymove 5s ease-in  infinite normal;
}
@keyframes mymove
{
    from {transform: rotate(0deg); background:red;}
    to {transform: rotate(360deg);background:pink;}
}

实列2

<!DOCTYPE html>
<html>
<head>
<style> 
div
{
width:200px;
height:200px;
background:red;
position:relative;
animation:myfirst 2s linear  infinite alternate;
/* Firefox: */
-moz-animation:myfirst 2s linear  infinite alternate;
/* Safari and Chrome: */
-webkit-animation:myfirst 2s linear infinite alternate;
/* Opera: */
-o-animation:myfirst 2s linear  infinite alternate;
}

@keyframes myfirst
{
0%   {background:red; left:0px; top:0px;}
25%  {background:yellow; left:200px; top:0px;}
50%  {background:blue; left:200px; top:200px;}
75%  {background:green; left:0px; top:200px;}
100% {background:red; left:0px; top:0px;}
}

@-moz-keyframes myfirst /* Firefox */
{
0%   {background:red; left:0px; top:0px;}
25%  {background:yellow; left:200px; top:0px;}
50%  {background:blue; left:200px; top:200px;}
75%  {background:green; left:0px; top:200px;}
100% {background:red; left:0px; top:0px;}
}

@-webkit-keyframes myfirst /* Safari and Chrome */
{
0%   {background:red; left:0px; top:0px;}
25%  {background:yellow; left:200px; top:0px;}
50%  {background:blue; left:200px; top:200px;}
75%  {background:green; left:0px; top:200px;}
100% {background:red; left:0px; top:0px;}
}

@-o-keyframes myfirst /* Opera */
{
0%   {background:red; left:0px; top:0px;}
25%  {background:yellow; left:200px; top:0px;}
50%  {background:blue; left:200px; top:200px;}
75%  {background:green; left:0px; top:200px;}
100% {background:red; left:0px; top:0px;}
}
</style>
</head>
<body>


<div></div>

</body>
</html>

猜你喜欢

转载自blog.csdn.net/YaoQing222/article/details/107937645