css实现3d旋转图片魔方
代码部分:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style type="text/css">
*{margin: 0;padding: 0;}
ul li{list-style: none;}
div{margin: 100px auto;width: 600px;height: 600px;position: relative;perspective: 1100px;}
ul{width: 300px;height: 300px; position: absolute;left: 0;top: 0;bottom: 0;right: 0;margin: auto;transform-style: preserve-3d;/*捆绑动画 a为动画名 一次播放共5s linear为匀速播放 infinite为无限循环播放 */animation: a 5s linear infinite;}
li{width: 300px;height: 300px;position: absolute;}
li:nth-child(1){background: url("image/7.jpg") ;background-size: 100% 100%;transform: translateY(-150px) rotateX(90deg);}
li:nth-child(2){background: url("image/8.jpg");background-size: 100% 100%;transform: translateY(150px) rotateX(-90deg);}
li:nth-child(3){background: url("image/9.jpg");background-size: 100% 100%;transform: translateX(-150px) rotateY(-90deg);}
li:nth-child(4){background: url("image/12.jpg");background-size: 100% 100%;transform: translateX(150px) rotateY(90deg);}
li:nth-child(5){background: url("image/11.jpg");background-size: 100% 100%;transform:translateZ(150px);}
li:nth-child(6){background: url("image/10.jpg");background-size: 100% 100%;transform: translateZ(-150px) rotateY(180deg);}
/*设置动画*/
@keyframes a{
0%{transform: rotateX(0deg) rotateY(0deg);} /*从原始位置开始*/
100%{transform: rotateX(360deg) rotateY(360deg);} /*到x y各旋转360度结束*/
}
</style>
</head>
<body>
<div>
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</body>
</html>