css布局实现三维按钮旋转点击破碎动画效果代码

代码语言:html

所属分类:粒子

代码描述:css布局实现三维按钮旋转点击破碎动画效果代码

代码标签: 三维 按钮 旋转 点击 破碎 动画 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开


<!DOCTYPE html>
<html lang="en" >

<head>

  <meta charset="UTF-8">
  

  
  
  
<style>
@import url("https://fonts.googleapis.com/css2?family=Train+One&display=swap");
*, *::before, *::after {
  padding: 0;
  margin: 0 auto;
  box-sizing: border-box;
}

body {
  background-color: #111;
  color: #fff;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  perspective: 750px;
  overflow: hidden;
}

input[type=checkbox] {
  -webkit-appearance: none;
     -moz-appearance: none;
          appearance: none;
  position: fixed;
  top: 1%;
  left: 1%;
  top: -100%;
  left: -100%;
  visibility: hidden;
}

.scene {
  position: relative;
  width: 400px;
  height: 150px;
  transform: translate(-50%, -50%);
  transform-style: preserve-3d;
  cursor: pointer;
  -webkit-animation: sceneRotate 16s infinite ease-in-out;
          animation: sceneRotate 16s infinite ease-in-out;
}
@-webkit-keyframes sceneRotate {
  0% {
    transform: rotateY(0deg);
  }
  50% {
    transform: rotateY(-180deg);
  }
  100% {
    transform: rotateY(-360deg);
  }
}
@keyframes sceneRotate {
  0% {
    transform: rotateY(0deg);
  }
  50% {
    transform: rotateY(-180deg);
  }
  100% {
    transform: rotateY(-360deg);
  }
}

.btn > div {
  position: absolute;
  width: 50px;
  height: 50px;
  overflow: hidden;
  transition-property: transform, opacity;
}
.btn > div::after {
  content: "Click me";
  font-family: "Train One", cursive;
  position: absolute;
  width: 400px;
  height: 150px;
  font-size: 80px;
  white-space: nowrap;
  display: flex;
  justify-content: center;
  align-items: center;
}
.btn-a > div:nth-child(1), .btn-c > div:nth-child(1) {
  top: 0px;
  left: 0px;
}
.btn-b > div:nth-child(1), .btn-d > div:nth-child(1) {
  top: 0px;
  left: 350px;
}
.btn > div:nth-child(1)::after {
  transform: translate(0px, 0px);
}
.btn-a > div:nth-child(9), .btn-c > div:nth-child(9) {
  top: 50px;
  left: 0px;
}
.btn-b > div:nth-child(9), .btn-d > div:nth-child(9) {
  top: 50px;
  left: 350px;
}
.btn > div:nth-child(9)::after {
  transform: translate(0px, -50px);
}
.btn-a > div:nth-child(17), .btn-c > div:nth-child(17) {
  top: 100px;
  left: 0px;
}
.btn-b > div:nth-child(17), .btn-d > div:nth-child(17) {
  top: 100px;
  left: 350px;
}
.btn > div:nth-child(17)::after {
  transform: translate(0px, -100px);
}
.btn-a > div:nth-child(2), .btn-c > div:nth-child(2) {
  top: 0px;
  left: 50px;
}
.btn-b > div:nth-child(2), .btn-d > div:nth-child(2) {
  top: 0px;
  left: 300px;
}
.btn > div:nth-child(2)::after {
  transform: translate(-50px, 0px);
}
.btn-a > div:nth-child(10), .btn-c > div:nth-child(10) {
  top: 50px;
  left: 50px;
}
.btn-b > div:nth-child(10), .btn-d > div:nth-child(10) {
  top: 50px;
  left: 300px;
}
.btn > div:nth-child(10)::after {
  transform: translate(-50px, -50px);
}
.btn-a > div:nth-child(18), .btn-c > div:nth-child(18) {
  top: 100px;
  left: 50px;
}
.btn-b > div:nth-child(18), .btn-d > div:nth-child(18) {
  top: 100px;
  left: 300px;
}
.btn > div:nth-child(18)::after {
  transform: translate(-50px, -100px);
}
.btn-a > div:nth-child(3), .btn-c > div:nth-child(3) {
  top: 0px;
  left: 100px;
}
.btn-b > div:nth-child(3), .btn-d > div:nth-child(3) {
  top: 0px;
  left: 250px;
}
.btn > div:nth-child(3)::after {
  transform: translate(-100px, 0px);
}
.btn-a > div:nth-child(11), .btn-c > div:nth-child(11) {
  top: 50px;
  left: 100px;
}
.btn-b > div:nth-child(11), .btn-d > div:nth-child(11) {
  top: 50px;
  left: 250px;
}
.btn > div:nth-child(11)::after {
  transform: translate(-100px, -50px);
}
.btn-a > div:nth-child(19), .btn-c > div:nth-child(19) {
  top: 100px;
  left: 100px;
}
.btn-b > div:nth-child(19), .btn-d > div:nth-child(19) {
  top: 100px;
  left: 250px;
}
.btn > div:nth-child(19)::after {
  transform: translate(-100px, -100px);
}
.btn-a > div:nth-child(4), .btn-c > div:nth-child(4) {
  top: 0px;
  left: 150px;
}
.btn-b > div:nth-child(4), .btn-d > div:nth-child(4) {
  top: 0px;
  left: 200px;
}
.btn > div:nth-child(4)::after {
  transform: translate(-150px, 0px);
}
.btn-a > div:nth-child(12), .btn-c > div:nth-child(12) {
  top: 50px;
  left: 150px;
}
.btn-b > div:nth-child(12), .btn-d > div:nth-child(12) {
  top: 50px;
  left: 200px;
}
.btn > div:nth-child(12)::after {
  transform: translate(-150px, -50px);
}
.btn-a > div:nth-child(20), .btn-c > div:nth-child(20) {
  top: 100px;
  left: 150px;
}
.btn-b > div:nth-child(20), .btn-d > div:nth-child(20) {
  top: 100px;
  left: 200px;
}
.btn > div:nth-child(20)::after {
  transform: translate(-150px, -100px);
}
.btn-a > div:nth-child(5), .btn-c > div:nth-child(5) {
  top: 0px;
  left: 200px;
}
.btn-b > div:nth-child(5), .btn-d > div:nth-child(5) {
  top: 0px;
  left: 150px;
}
.btn > div:nth-child(5)::after {
  transform: translate(-200px, 0px);
}
.btn-a > div:nth-child(13), .btn-c > div:nth-child(13) {
  top: 50px;
  left: 200px;
}
.btn-b > div:nth-child(13), .btn-d > div:nth-child(13) {
  top: 50px;
  left: 150px;
}
.btn > div:nth-child(13)::after {
  transform: translate(-200px, -50px);
}
.btn-a > div:nth-child(21), .btn-c > div:nth-child(21) {
  top: 100px;
  left: 200px;
}
.btn-b > div:nth-child(21), .btn-d > div:nth-child(21) {
  top: 100px;
  left: 150px;
}
.btn > div:nth-child(21)::after {
  transform: translate(-200px, -100px);
}
.btn-a > div:nth-child(6), .btn-c > div:nth-child(6) {
  top: 0px;
  left: 250px;
}
.btn-b > div:nth-child(6), .btn-d > div:nth-child(6) {
  top: 0px;
  left: 100px;
}
.btn > div:nth-child(6)::after {
  transform: translate(-250px, 0px);
}
.btn-a > div:nth-child(14), .btn-c > div:nth-child(14) {
  top: 50px;
  left: 250px;
}
.btn-b > div:nth-child(14), .btn-d > div:nth-child(14) {
  top: 50px;
  left: 100px;
}
.btn > div:nth-child(14)::after {
  transform: translate(-250px, -50px);
}
.btn-a > div:nth-child(22), .btn-c > div:nth-child(22) {
  top: 100px;
  left: 250px;
}
.btn-b > div:nth-child(22), .btn-d > div:nth-child(22) {
  top: 100px;
  left: 100px;
}
.btn > div:nth-child(22)::after {
  transform: translate(-250px, -100px);
}
.btn-a > div:nth-child(7), .btn-c > div:nth-child(7) {
  top: 0px;
  left: 300px;
}
.btn-b > div:nth-child(7), .btn-d > div:nth-child(7) {
  top: 0px;
  left: 50px;
}
.btn > div:nth-child(7)::after {
  transform: translate(-300px, 0px);
}
.btn-a > div:nth-child(15), .btn-c > div:nth-child(15) {
  top: 50px;
  left: 300px;
}
.btn-b > div:nth-child(15), .btn-d > div:nth-child(15) {
  top: 50px;
  left: 50px;
}
.btn > div:nth-child(15)::after {
  transform: translate(-300px, -50px);
}
.btn-a > div:nth-child(23), .btn-c > div:nth-child(23) {
  top: 100px;
  left: 300px;
}
.btn-b > div:nth-child(23), .btn-d > div:nth-child(23) {
  top: 100px;
  left: 50px;
}
.btn > div:nth-child(23)::after {
  transform: translate(-300px, -100px);
}
.btn-a > div:nth-child(8), .btn-c > div:nth-child(8) {
  top: 0px;
  left: 350px;
}
.btn-b > div:nth-child(8), .btn-d > div:nth-child(8) {
  top: 0px;
  left: 0px;
}
.btn > div:nth-child(8)::after {
  transform: translate(-350px, 0px);
}
.btn-a > div:nth-child(16), .btn-c > div:nth-child(16) {
  top: 50px;
  left: 350px;
}
.btn-b > div:nth-child(16), .btn-d > div:nth-child(16) {
  top: 50px;
  left: 0px;
}
.btn > div:nth-child(16)::after {
  transform: translate(-350px, -50px);
}
.btn-a > div:nth-child(24), .btn-c > div:nth-child(24) {
  top: 100px;
  left: 350px;
}
.btn-b > div:nth-child(24), .btn-d > div:nth-child(24) {
  top: 100px;
  left: 0px;
}
.btn > div:nth-child(24)::after {
  transform: translate(-350px, -100px);
}
.btn-a > div {
  background-color: #880E4F;
}
.btn-b > div {
  background-color: #AD1457;
}
.btn-c > div {
  background-color: #33691E;
}
.btn-d > div {
  background-color: #558B2F;
}

input[type=checkbox]:not(:checked) + label .btn-a > div,
input[type=checkbox]:checked + label .btn-c > div {
  transform: translateZ(1px);
  transition-duration: 2s;
  transition-delay: 0.5s;
  transition-timing-function: ease-in-out;
}

input[type=checkbox]:not(:checked) + label .btn-b > div,
input[type=checkbox]:checked + label .btn-d > div {
  transform: translateZ(-1px) rotateY(180deg);
  transition-duration: 2s;
  transition-delay: 0.5s;
  transition-timing-function: ease-in-out;
}

input[type=checkbox]:not(:checked) + label .btn-c > div,
input[type=checkbox]:not(:checked) + label .btn-d > div,
input[type=checkbox]:checked + label .btn-a > div,
input[type=checkbox]:checked + label .btn-b > div {
  transition-duration: 2.5s;
  transition-delay: 0s;
  transition-timing-function: ease-out;
  opacity: 0.5;
}

input[type=checkbox]:checked + label .btn-a > div:nth-child(1) {
  transform: translate3d(0.6944444444px, 345.9027777778px, -165px) rotateX(604deg) rotateY(584deg) rotateZ(667deg);
}

input[type=checkbox]:checked + label .btn-b > div:nth-child(1) {
  transform: translate3d(-165.0694444444px, 247.2916666667px, -319.6527777778px) rotateX(510deg) rotateY(359deg) rotateZ(529deg);
}

input[type=checkbox]:not(:checked) + label .btn-c > div:nth-child(1) {
  transform: translate3d(259.2361111111px, 121.4583333333px, -302.7083333333px) rotateX(374deg) rotateY(157deg) rotateZ(351deg);
}

input[type=checkbox]:not(:checked) + label .btn-d > div:nth-child(1) {
  transform: translate3d(128.8888888889px, -50.1388888889px, -284.4444444444px) rotateX(505deg) rotateY(234deg) rotateZ(676deg);
}

input[type=checkbox]:checked + label .btn-a > div:nth-child(9) {
  transform: translate3d(-188.75px, -124.0277777778px, 294.9305555556px) rotateX(335deg) rotateY(130deg) rotateZ(195deg);
}

input[type=checkbox]:checked + label .btn-b > div:nth-child(9) {
  transform: translate3d(-179.7916666667px, 51.4583333333px, -51.1805555556px) rotateX(223deg) rotateY(282deg) rotateZ(359deg);
}

input[type=checkbox]:not(:checked) + label .btn-c > div:nth-child(9) {
  transform: translate3d(29.5833333333px, 154.2361111111px, 43.2638888889px) rotateX(33deg) rotateY(94deg) rotateZ(423deg);
}

input[type=checkbox]:not(:checked) + label .btn-d > div:nth-child(9) {
  transform: translate3d(52.5px, -342.8472222222px, 325.4861111111px) rotateX(588deg) rotateY(110deg) rotateZ(449deg);
}

input[type=checkbox]:checked + label .btn-a > div:nth-child(17) {
  transform: translate3d(298.3333333333px, -145.2777777778px, 267.6388888889px) rotateX(476deg) rotateY(676deg) rotateZ(674deg);
}

input[type=checkbox]:checked + label .btn-b > div:nth-child(17) {
  transform: translate3d(29.6527777778px, -252.2222222222px, -315.9722222222px) rotateX(45deg) rotateY(148deg) rotateZ(133deg);
}

input[type=checkbox]:not(:checked) + label .btn-c > div:nth-child(17) {
  transform: translate3d(-74.3055555556px, 199.1666666667px, 47.2222222222px) rotateX(493deg) rotateY(379deg) rotateZ(631deg);
}

input[type=checkbox]:not(:checked) + label .btn-d > div:nth-child(17) {
  transform: translate3d(-116.875px, 339.0972222222px, 316.5972222222px) rotateX(263deg) rotateY(246deg) rotateZ(12deg);
}

input[type=checkbox]:checked + label .btn-a > div:nth-child(2) {
  transform: translate3d(-40.9027777778px, 10.2083333333px, 111.25px) rotateX(715deg) rotateY(404deg) rotateZ(43deg);
}

input[type=checkbox]:checked + label .btn-b > div:nth-child(2) {
  transform: translate3d(-265.5555555556px, -329.2361111111px, -309.2361111111px) rotateX(671deg) rotateY(334deg) rotateZ(650deg);
}

input[type=checkbox]:not(:checked) + label .btn-c > div:nth-child(2) {
  transform: translate3d(-269.0972222222px, -160.4861111111px, -231.9444444444px) rotateX(367deg) rotateY(281deg) rotateZ(675deg);
}

input[type=checkbox]:not(:checked) + label .btn-d > div:nth-child(2) {
  transform: translate3d(163.4027777778px, 295.625px, 172.9861111111px) rotateX(302deg) rotateY(498deg) rotateZ(495deg);
}

input[type=checkbox]:checked + label .btn-a > div:nth-child(10) {
  transform: translate3d(-115.4861111111px, 260.4166666667px, -123.1944444444px) rotateX(671deg) rotateY(218deg) rotateZ(188deg);
}

input[type=checkbox]:checked + label .btn-b > div:nth-child(10) {
  transform: translate3d(317.6388888889px, 106.5277777778px, -240.2083333333px) rotateX(690deg) rotateY(511deg) rotateZ(556deg);
}

input[type=checkbox]:not(:checked) + label .btn-c > div:nth-child(10) {
  transform: translate3d(-143.0555555556px, 291.3888888889px, 104.0277777778px) rotateX(23deg) rotateY(8deg) rotateZ(672deg);
}

input[type=checkbox]:not(:checked) + label .btn-d > div:nth-child(10) {
  transform: translate3d(-140.3472222222px, 336.7361111111px, -8.75px) rotateX(515deg) rotateY(23deg) rotateZ(604deg);
}

input[type=checkbox]:checked + label .btn-a > div:nth-child(18) {
  transform: translate3d(179.9305555556px, 16.6666666667px, 109.5833333333px) rotateX(713deg) rotateY(472deg) rotateZ(292deg);
}

input[type=checkbox]:checked + label .btn-b > div:nth-child(18) {
  transform: translate3d(54.5138888889px, -112.8472222222px, -126.4583333333px) rotateX(309deg) rotateY(233deg) rotateZ(546deg);
}

input[type=checkbox]:not(:checked) + label .btn-c > div:nth-child(18) {
  transform: translate3d(-11.0416666667px, 221.1805555556px, 160.3472222222px) rotateX(465deg) rotateY(295deg) rotateZ(621deg);
}

input[type=checkbox]:not(:checked) + label .btn-d > div:nth-child(18) {
  transform: translate3d(98.75px, -298.1944444444px, -147.4305555556px) rotateX(688deg) rotateY(111deg) rotateZ(197deg);
}

input[type=checkbox]:checked + label .btn-a > div:nth-child(3) {
  transform: translate3d(-283.9583333333px, -328.3333333333px, 332.1527777778px) rotateX(346deg) rotateY(467deg) rotateZ(611deg);
}

input[type=checkbox]:checked + label .btn-b > div:nth-child(3) {
  transform: translate3d(77.7777777778px, -298.4722222222px, -329.6527777778px) rotateX(87deg) rotateY(61deg) rotateZ(181deg);
}

input[type=checkbox]:not(:checked) + label .btn-c > div:nth-child(3) {
  transform: translate3d(-31.9444444444px, -296.875px, -45.9027777778px) rotateX(658deg) rotateY(417deg) rotateZ(183deg);
}

input[type=checkbox]:not(:checked) + label .btn-d > div:nth-child(3) {
  transform: translate3d(-325.4166666667px, 66.7361111111px, 32.9861111111px) rotateX(265deg) rotateY(379deg) rotateZ(396deg);
}

input[type=checkbox]:checked + label .btn-a > div:nth-child(11) {
  transform: translate3d(-74.7222222222px, 77.9861111111px, 181.3194444444px) rotateX(539deg) rotateY(270deg) rotateZ(272deg);
}

input[type=checkbox]:checked + label .btn-b > div:nth-child(11) {
  transform: translate3d(292.0833333333px, -142.9861111111px, 106.7361111111px) rotateX(49deg) rotateY(21deg) rotateZ(265deg);
}

input[type=checkbox]:not(:checked) + label .btn-c > div:nth-child(11) {
  transform: translate3d(207.5px, 176.1111111111px, -267.9166666667px) rotateX(198deg) rotateY(364deg) rotateZ(508deg);
}

input[type=checkbox]:not(:checked) + label .btn-d > div:nth-child(11) {
  transform: translate3d(279.1666666667px, -104.51388.........完整代码请登录后点击上方下载按钮下载查看

网友评论0