css布局实现炫酷魔方旋转效果
代码语言:html
所属分类:三维
代码描述:css布局实现炫酷魔方旋转效果
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
html,
body {
margin: 0;
overflow: hidden;
}
.main__wrapper {
position: fixed;
font-size: calc(1em + 5vw);
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.rubixcube__scene {
position: fixed;
-webkit-perspective: 4em;
perspective: 4em;
width: 4em;
height: 4em;
top: 47.5%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
border-radius: 50%;
border: 0.5em solid rgba(0, 0, 0, 0.01);
}
.rubixcube__scene:hover .rubixcube__scene--overlay:after {
content: "Rubix Cube";
position: absolute;
font-family: Lato;
white-space: nowrap;
font-size: calc(0.5em + 5vw);
font-weight: bold;
top: 47.5%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.rubix {
position: relative;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
width: 4em;
height: 4em;
-webkit-transform: translateZ(-2em) rotateY(36deg) rotateX(45deg);
transform: translateZ(-2em) rotateY(36deg) rotateX(45deg);
-webkit-transition: -webkit-transform 1s;
transition: -webkit-transform 1s;
transition: transform 1s;
transition: transform 1s, -webkit-transform 1s;
}
.rubix.show--front {
-webkit-transform: translateZ(-2em) rotateY(0deg);
transform: translateZ(-2em) rotateY(0deg);
}
.rubix.show--right {
-webkit-transform: translateZ(-2em) rotateY(-90deg);
transform: translateZ(-2em) rotateY(-90deg);
}
.rubix.show--back {
-webkit-transform: translateZ(-2em) rotateY(-180deg);
transform: translateZ(-2em) rotateY(-180deg);
}
.rubix.show--left {
-webkit-transform: translateZ(-2em) rotateY(90deg);
transform: translateZ(-2em) rotateY(90deg);
}
.rubix.show--top {
-webkit-transform: translateZ(-2em) rotateX(-90deg);
transform: translateZ(-2em) rotateX(-90deg);
}
.rubix.show--bottom {
-webkit-transform: translateZ(-2em) rotateX(90deg);
transform: translateZ(-2em) rotateX(90deg);
}
.rubix__face {
position: absolute;
box-sizing: border-box;
width: 1em;
height: 1em;
border: 0.075em solid black;
line-height: 4em;
font-size: 1em;
font-weight: bold;
--opacity: 0.75;
-webkit-transform-origin: 2em 2em;
transform-origin: 2em 2em;
color: white;
text-align: center;
border-radius: 0.1em;
}
.rubix__face--front {
background: rgba(255, 0, 0, var(--opacity));
-webkit-transform: rotateY(0deg) translateZ(2em);
transform: rotateY(0deg) translateZ(2em);
}
.rubix__face--front.rubix__face--row2 {
top: 1em;
}
.rubix__face--front.rubix__face--row3 {
top: 2em;
}
.rubix__face--front.rubix__face--row4 {
top: 3em;
}
.rubix__face--front.rubix__face--col2 {
left: 1em;
}
.rubix__face--front.rubix__face--col3 {
left: 2em;
}
.rubix__face--front.rubix__face--col4 {
left: 3em;
}
.rubix__face--right {
background: rgba(0, 255, 0, var(--opacity));
--x: 0;
-webkit-transform: rotateY(90deg) translateZ(2em) translateX(var(--x));
transform: rotateY(90deg) translateZ(2em) translateX(var(--x));
}
.rubix__face--right.rubix__face--row2 {
top: 1em;
}
.rubix__face--right.rubix__face--row3 {
top: 2em;
}
.rubix__face--right.rubix__face--row4 {
top: 3em;
}
.rubix__face--right.rubix__face--col2 {
--x: 1em;
}
.rubix__face--right.rubix__face--col3 {
--x: 2em;
}
.rubix__face--right.rubix__face--col4 {
--x: 3em;
}
.rubix__face--back {
background: rgba(0, 0, 255, var(--opacity));
-webkit-transform: rotateY(180deg) translateZ(2em);
transform: rotateY(180deg) translateZ(2em);
}
.rubix__face--back.rubix__face--row2 {
top: 1em;
}
.rubix__face--back.rubix__face--row3 {
top: 2em;
}
.rubix__face--back.rubix__face--row4 {
top: 3em;
}
.rubix__face--back.rubix__face--col2 {
left: -1em;
}
.rubix__face--back.rubix__face--col3 {
left: -2em;
}
.rubix__face--back.rubix__face--col4 {
left: -3em;
}
.rubix__face--left {
background: rgba(0, 255, 255, var(--opacity));
--x: 0;
-webkit-transform: rotateY(-90deg) translateZ(2em) translateX(var(--x));
transform: rotateY(-90deg) translateZ(2em) translateX(var(--x));
}
.rubix__face--left.rubix__face--row2 {
top: 1em;
}
.rubix__face--left.rubix__face--row3 {
top: 2em;
}
.rubix__face--left.rubix__face--row4 {
top: 3em;
}
.rubix__face--left.rubix__face--col2 {
--x: 1em;
}
.rubix__face--left.rubix__face--col3 {
--x: 2em;
}
.rubix__face--left.rubix__face--col4 {
--x: 3em;
}
.rubix__face--top {
background: rgba(255, 0, 255, var(--opacity));
--y: 0;
-webkit-transform: rotateX(90deg) translateZ(2em) translateY(var(--y));
transform: rotateX(90deg) translateZ(2em) translateY(var(--y));
}
.rubix__face--top.rubix__face--row2 {
--y: 1em;
}
.rubix__face--top.rubix__face--row3 {
--y: 2em;
}
.rubix__face--top.rubix__face--row4 {
--y: 3em;
}
.rubix__face--top.rubix__face--col2 {
left: 1em;
}
.rubix__face--top.rubix__face--col3 {
left: 2em;
}
.rubix__face--top.rubix__face--col4 {
left: 3em;
}
.rubix__face--bottom {
background: rgba(255, 255, 0, var(--opacity));
--y: 0;
-webkit-transform: rotateX(-90deg) translateZ(2em) translateY(var(--y));
transform: rotateX(-90deg) translateZ(2em) translateY(var(--y));
}
.rubix__face--bottom.rubix__face--row2 {
--y: 1em;
}
.rubix__face--bottom.rubix__face--row3 {
--y: 2em;
}
.rubix__face--bottom.rubix__face--row4 {
--y: 3em;
}
.rubix__face--bottom.rubix__face--col2 {
left: 1em;
}
.rubix__face--bottom.rubix__face--col3 {
left: 2em;
}
.rubix__face--bottom.rubix__face--col4 {
left: 3em;
}
</style>
</head>
<body translate="no" >
<div class="main__wrapper".........完整代码请登录后点击上方下载按钮下载查看
网友评论0