2021-6-10 前端达人
<!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>
作者:yuanzhuang
链接:https://www.jianshu.com/p/10c90c482795
来源:简书
蓝蓝设计建立了UI设计分享群,每天会分享国内外的一些优秀设计,如果有兴趣的话,可以进入一起成长学习,请扫码蓝小助,报下信息,蓝小助会请您入群。欢迎您加入噢~~希望得到建议咨询、商务合作,也请与我们联系。
蓝蓝设计( www.lanlanwork.com )是一家专注而深入的界面设计公司,为期望卓越的国内外企业提供卓越的UI界面设计、BS界面设计 、 cs界面设计 、 ipad界面设计 、 包装设计 、 图标定制 、 用户体验 、交互设计、 网站建设 、平面设计服务