實(shí)現(xiàn)的效果
可復(fù)制代碼
<!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;
? ? ? list-style: none;
? ? }
? ? html {
? ? ? height: 100%;
? ? }
? ? .container {
? ? ? width: 400px;
? ? ? margin: 200px auto;
? ? ? height: 100px;
? ? ? position: relative;
? ? }
? ? .box {
? ? ? width: 100px;
? ? ? height: 100px;
? ? ? position: absolute;
? ? ? float: left;
? ? }
? ? #rigth {
? ? ? background-color: rgba(0, 0, 0, 0.3);
? ? ? position: absolute;
? ? ? right: 0px;
? ? ? top: 50%;
? ? ? transform: translateY(-50%);
? ? }
? ? #left {
? ? ? position: absolute;
? ? ? left: 0px;
? ? ? background-color: rgba(0, 0, 0, 0.3);
? ? ? top: 50%;
? ? ? transform: translateY(-50%);
? ? }
? ? span:hover {
? ? ? cursor: pointer;
? ? ? color: red;
? ? }
? ? ul {
? ? ? width: 100px;
? ? ? height: 100px;
? ? ? transform-style: preserve-3d;
? ? ? float: left;
? ? ? transition: all 1s;
? ? }
? ? .top {
? ? ? background-color: red;
? ? ? transform: translateY(50px) rotateX(-90deg);
? ? ? transform: translateY(50px) rotateX(-90deg);
? ? ? background: url('./image/4.jpg') no-repeat;
? ? }
? ? .footer {
? ? ? transform: translateY(-50px) rotateX(90deg);
? ? ? background: url('./image/2.jpg') no-repeat;
? ? }
? ? .left {
? ? ? transform: translateX(50px) rotateY(90deg)
? ? }
? ? .rigth {
? ? ? background-color: yellow;
? ? ? transform: translateX(-50px) rotateY(-90deg);
? ? }
? ? .Front {
? ? ? background-color: pink;
? ? ? transform: translateZ(50px);
? ? ? background: url('./image/1.jpeg') no-repeat;
? ? }
? ? .behind {
? ? ? background-color: blue;
? ? ? transform: translateZ(-50px) rotateX(-180deg);
? ? ? background: url('./image/3.jpg') no-repeat;
? ? }
? ? /* 前 */
? ? .container ul:nth-child(2) .Front {
? ? ? background-position: -100px 0;
? ? }
? ? .container ul:nth-child(3) .Front {
? ? ? background-position: -200px 0;
? ? }
? ? .container ul:nth-child(4) .Front {
? ? ? background-position: -300px 0;
? ? }
? ? /* 底部 */
? ? .container ul:nth-child(2) .footer {
? ? ? background-position: -100px 0;
? ? }
? ? .container ul:nth-child(3) .footer {
? ? ? background-position: -200px 0;
? ? }
? ? .container ul:nth-child(4) .footer {
? ? ? background-position: -300px 0;
? ? }
? ? /* 后面 */
? ? .container ul:nth-child(2) .behind {
? ? ? background-position: -100px 0;
? ? }
? ? .container ul:nth-child(3) .behind {
? ? ? background-position: -200px 0;
? ? }
? ? .container ul:nth-child(4) .behind {
? ? ? background-position: -300px 0;
? ? }
? ? /* 上面 */
? ? .container ul:nth-child(2) .top {
? ? ? background-position: -100px 0;
? ? }
? ? .container ul:nth-child(3) .top {
? ? ? background-position: -200px 0;
? ? }
? ? .container ul:nth-child(4) .top {
? ? ? background-position: -300px 0;
? ? }
? </style>
</head>
<body>
? <div class="container">
? ? <ul>
? ? ? <li class="box top"></li>
? ? ? <li class="box footer"></li>
? ? ? <li class="box left"></li>
? ? ? <li class="box rigth"></li>
? ? ? <li class="box Front"></li>
? ? ? <li class="box behind"></li>
? ? </ul>
? ? <ul>
? ? ? <li class="box top"></li>
? ? ? <li class="box footer"></li>
? ? ? <li class="box left"></li>
? ? ? <li class="box rigth"></li>
? ? ? <li class="box Front"></li>
? ? ? <li class="box behind"></li>
? ? </ul>
? ? <ul>
? ? ? <li class="box top"></li>
? ? ? <li class="box footer"></li>
? ? ? <li class="box left"></li>
? ? ? <li class="box rigth"></li>
? ? ? <li class="box Front"></li>
? ? ? <li class="box behind"></li>
? ? </ul>
? ? <ul>
? ? ? <li class="box top"></li>
? ? ? <li class="box footer"></li>
? ? ? <li class="box left"></li>
? ? ? <li class="box rigth"></li>
? ? ? <li class="box Front"></li>
? ? ? <li class="box behind"></li>
? ? </ul>
? ? <span id="rigth">下張</span>
? ? <span href="JavaScript:;" id="left">上張</span>
? </div>
</body>
<script>
? var rigth = document.getElementById("rigth")
? var left = document.getElementById("left")
? var ul = document.querySelectorAll(".container ul")
? var index = 0
? var flags = false
? rigth.onclick = function () {
? ? if (flags == false) {
? ? ? flags = true
? ? ? index++
? ? ? for (var i = 0; i < ul.length; i++) {
? ? ? ? ul[i].style.transform = "rotateX(" + index * 90 + "deg)"
? ? ? ? ul[i].style.transitionDelay = "" + i * 0.3 + "s"
? ? ? }
? ? ? setTimeout(function () {
? ? ? ? flags = false
? ? ? }, 2000)
? ? }
? }
? left.onclick = function () {
? ? if (flags == false) {
? ? ? flags = true
? ? ? index--
? ? ? for (var i = 0; i < ul.length; i++) {
? ? ? ? ul[i].style.transform = "rotateX(" + index * 90 + "deg)"
? ? ? ? ul[i].style.transitionDelay = "" + i * 0.3 + "s"
? ? ? }
? ? ? setTimeout(function () {
? ? ? ? flags = false
? ? ? }, 2000)
? ? }
? }
</script>
</html>