css动画的三种方式
- animation
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
width: 50px;
height: 50px;
background: #f40;
border-radius: 50%;
/* animation: mymove 2s; */
animation: mymove;
/* 时长 */
animation-duration: 3s;
/* 动画的过渡类型*/
animation-timing-function: ease-in-out;
/* 延时 */
animation-delay: 2s;
/* 无限循环 */
animation-iteration-count: infinite;
/* 反复执行 */
/* animation-direction: alternate; */
}
@keyframes mymove {
0% {
width: 50px;
height: 50px;
}
50% {
width: 100px;
height: 100px;
}
100% {
width: 50px;
height: 50px;
}
}
</style>
</head>
<body>
<div></div>
</body>
</html>
- transition
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/* 简写 */
/* transition: property duration timing-function delay; */
/* div {
transition: all 1s ease-in-out 2s;
} */
div {
width: 100px;
height: 100px;
border-radius: 50%;
background: #f40;
/* 时长 */
transition-duration: 1s;
/* 只给width加动画 默认值为all */
transition-property: width;
/* 开始时间 */
transition-delay: 1s;
}
div:hover {
height: 150px;
width: 150px;
}
</style>
</head>
<body>
<div></div>
<script>
</script>
</body>
</html>
- transform
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
img {
margin-left: 50px;
width: 50px;
height: 50px;
border-radius: 50%;
border: 1px red solid;
}
@keyframes rotate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
@keyframes rotateX {
0% {
transform: rotateX(0deg);
}
100% {
transform: rotateX(360deg);
}
}
@keyframes rotateY {
0% {
transform: rotateY(0deg);
}
100% {
transform: rotateY(360deg);
}
}
.rotate {
animation: rotate 2s infinite linear;
}
.rotateX {
animation: rotateX 2s infinite linear;
}
.rotateY {
animation: rotateY 2s infinite linear;
}
</style>
</head>
<body>
<img src="../../1139013-20190722143239200-1071707775.png" alt="" class="rotate">
<img src="../../1139013-20190722143239200-1071707775.png" alt="" class="rotateX">
<img src="../../1139013-20190722143239200-1071707775.png" alt="" class="rotateY">
</body>
</html>