No.5 - 순수 CSS로 중축을 중심으로 회전하는 입방체 만들기
body{
background-color: #000;
margin: 0;
padding: 0;
}
main{
perspective: 800px;
}
.cube{
transform-style: preserve-3d;
position: relative;
margin: 200px auto 0px;
width: 400px;
height: 400px;
animation: spin 8s linear infinite;
animation-play-state: paused;
}
.cube>div{
background-color: blue;
opacity: 0.3;
position: absolute;
outline: 3px solid #0af;
width: 400px;
height:400px;
}
.cube>div:nth-child(1){
transform: translateZ(200px);
}
.cube>div:nth-child(2){
transform: rotateY(180deg) translateZ(200px);
}
.cube>div:nth-child(3){
transform: rotateY(90deg) translateZ(200px);
}
.cube>div:nth-child(4){
transform: rotateY(-90deg) translateZ(200px);
}
.cube>div:nth-child(5){
transform: rotateX(90deg) translateZ(200px);
}
.cube>div:nth-child(6){
transform: rotateX(-90deg) translateZ(200px);
}
@keyframes spin{
100%{transform: rotateY(-360deg);}
}
.cube:hover{
animation-play-state: running;
}
DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> CSS title>
<link rel="stylesheet" href="style.css">
head>
<body>
<main>
<div class="cube">
<div>div>
<div>div>
<div>div>
<div>div>
<div>div>
<div>div>
div>
main>
body>
html>
중점을 두다
① 여러 요소 absolute에 중첩
②transform: rotateY(180deg) translateZ(200px);transform:translateZ(200px)rotateY(180deg);
선후의 차이는 커다란 차이가 있다!
.cube>div:nth-child(1){
transform: translateZ(200px);
}
.cube>div:nth-child(2){
transform: rotateY(180deg) translateZ(200px);
}
.cube>div:nth-child(3){
transform: rotateY(90deg) translateZ(200px);
}
.cube>div:nth-child(4){
transform: rotateY(-90deg) translateZ(200px);
}
.cube>div:nth-child(5){
transform: rotateX(90deg) translateZ(200px);
}
.cube>div:nth-child(6){
transform: rotateX(-90deg) translateZ(200px);
}
먼저 중점에서 회전한 다음에 각자 변화한 Z방향으로 200px를 추진한다.
200px를 집단적으로 추진한 후 중점에서 회전하는 것이 아니다.
③margin:200px auto 0px;
④ 3D 무대 요소는 시각에 결정적(body와 같은 큰 배경 좌석 무대 요소는 화면에 더욱 진실한 효과를 낸다)
⑤
animation: name duration timing-function delay iteration-count direction;
animation-play-state: paused;
animation-play-state: running;
@keyframes myfirst
{
0% {background: red; left:0px; top:0px;}
25% {background: yellow; left:200px; top:0px;}
50% {background: blue; left:200px; top:200px;}
75% {background: green; left:0px; top:200px;}
100% {background: red; left:0px; top:0px;}
}
.cube:hover{
animation-play-state: running;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.