钟摆案例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
.box{
width:150px;
height:400px;
background: url("clock.png") no-repeat;
margin: auto;
/* animation : 动画的名字 时间 匀速 无限 */
animation:move 2s linear infinite;
transform-origin: top center;
}
/* @keyframes: 自定义动画 */
@keyframes move{
0%{
transform: rotate(0deg);
}
25%{
transform: rotate(45deg);
}
50%{
transform: rotate(0deg);
}
75%{
transform: rotate(-45deg);
}
100%{
transform: rotate(0deg);
}
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
3D魔方案例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
body{
background: yellow;
}
.box{
width: 320px;
height: 560px;
margin: 100px auto;
background: url('./img/zf_cubeBg.jpg') no-repeat 100% 100%;
/* 视距 */
perspective: 3000px;
}
.list{
position: relative;
transform-style: preserve-3d;
width: 100%;
height: 100%;
list-style: none;
animation: move 6s infinite;
transform: rotateY(90deg);
}
@keyframes move {
0%{
transform: translate(200px) rotateX(90deg);
}
50%{
transform: translate(100px) rotateY(180deg);
}
100%{
transform: translateY(100px) rotateZ(45deg);
}
}
.list li{
width: 200px;
height: 200px;
position: absolute;
left: 50%;
top: 50%;
margin-top: -100px;
margin-left: -100px;
}
.list li:nth-child(1){
transform: translateZ(100px);
}
.list li:nth-child(2){
transform: translateZ(-100px) rotateY(180deg);
}
.list li:nth-child(3){
transform: translateY(100px) rotateX(-90deg);
}
.list li:nth-child(4){
transform: translateY(-100px) rotateX(90deg);
}
/* 从正轴向负轴看,逆时针负,顺时针为正;*/
.list li:nth-child(5){
transform: translateX(100px) rotateY(90deg);
}
.list li:nth-child(6){
transform: translateX(-100px) rotateY(-90deg);
}
.list li img{
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div class="box">
<ul class="list">
<li><img src="./img/zf_cube1.png" alt=""></li>
<li><img src="./img/zf_cube2.png" alt=""></li>
<li><img src="./img/zf_cube3.png" alt=""></li>
<li><img src="./img/zf_cube4.png" alt=""></li>
<li><img src="./img/zf_cube5.png" alt=""></li>
<li><img src="./img/zf_cube6.png" alt=""></li>
</ul>
</div>
</body>
</html>