CSS3多面體3D運動效果

antzone發表於2018-06-20

分享一段程式碼例項,它實現了多面體立體運動效果。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style>
body {
  background: black;
}
.container {
  width: 200px;
  height: 173.2px;
  position: relative;
  margin: 200px auto;
  transform-style: preserve-3d;
}
.container div {
  width: 200px;
  height: 173.2px;
  position: absolute;
  clip-path: polygon(50% 0,100% 100%,0 100%);
}
.container div:nth-child(1) {
  transform: rotateX(-70.5deg);
  transform-origin: 0 100%;
}
.container div:nth-child(2) {
  transform: rotate3d(100, -173.2, 0, 70.5deg);
  transform-origin: 0 100%;
}
.container div:nth-child(3) {
  transform: rotate3d(-100, -173.2, 0, -70.5deg);
  transform-origin: 100% 100%;
}
.container div:nth-child(1) {
  background: rgba(255,0,0,0.9);
}
.container div:nth-child(2) {
  background: rgba(0,255,0,0.9);
}
.container div:nth-child(3) {
  background: rgba(0,0,255,0.9);
}
.container div:nth-child(4) {
  background: rgba(0,255,255,0.9);
}
@keyframes rotate {
  from {
    transform: rotate3d(1,1,1,0);
  }
  to {
    transform: rotate3d(1,1,1,360deg);
  }
}
.container {
  animation: rotate 5s linear infinite;
}
</style>
</head>
<body>
  <div class="container">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
  </div>
</body>
</html>

相關文章