css+div实现可点击打开的礼品盒堆积效果代码

代码语言:html

所属分类:其他

代码描述:css+div实现可点击打开的礼品盒堆积效果代码

代码标签: css div 可点击 打开 礼品盒 堆积

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


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

<head>

  <meta charset="UTF-8">

  
<style>
* { margin: 0; padding: 0; box-sizing: border-box }
body { 
  height: 100vh; 
  display: grid; 
  place-items: center; 
  position: relative;
  overflow: hidden;
  background-color: #060606;
}
body::after{
  content: "";
  position: absolute;
  inset: 0;
  background-image: url(//repo.bfw.wiki/bfwrepo/image/638847feeeebb.png);
background-size: cover;
  z-index: -1;
  transform: scale(1.1);
  filter: blur(5px);
  opacity: 0.25; 
}
.scene { perspective: 1500px }
.scene * { transform-style: preserve-3d }

.tree {
  --width: 80vmin;
  --gap: 2vmin;
  --columns: 14;
  width: var(--width);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(var(--columns), 1fr);
  gap: var(--gap);
  --box-size: calc(((var(--width) - (var(--columns) - 1) * var(--gap)) / 14) * 2 + var(--gap));
  counter-reset: days 25;
  direction: rtl
}

.tree > .box {
  grid-column: var(--gcs, auto) / span 2;
  display: grid;  
  outline: 1px solid transparent;
  counter-increment: days -1;
}

.tree > .box:nth-child(1) { --gcs: 7 }
.tree > .box:nth-child(2) { --gcs: 6 }
.tree > .box:nth-child(4) { --gcs: 5 }
.tree > .box:nth-child(7) { --gcs: 4 }
.tree > .box:nth-child(11){ --gcs: 3 }
.tree > .box:nth-child(16){ --gcs: 2 }
.tree > .box:nth-child(22){ --gcs: 5 }

/* sides */
.tree > .box > p { 
  grid-area: 1/1; 
  display: grid; 
  background-color: var(--wrap);
  --ribbon-grad: 
    transparent 30%, var(--ribbon) 30% 37%, var(--wrap) 37% 38%, var(--ribbon) 38% 62%, 
    var(--wrap) 62% 63%, var(--ribbon) 63% 70%, transparent 70%;
  background-image: 
    linear-gradient(var(--l1, transparent) 100%, transparent 0),
    linear-gradient(90deg, var(--ribbon-grad)), 
    linear-gradient(0deg, var(--ribbon-grad)),
    repeating-linear-gradient(90deg, transparent 0 3%, rgb(0 0 0 / .125) 3% 5%, transparent 5% 8%);
  --transform: rotateY(var(--ry, 0deg)) rotateX(var(--rx, 0deg)) translateZ(calc(var(--box-size) * .5));
  transform: var(--transform); 
}

.tree > .box > p:nth-child(2) { --ry: 180deg; --l2: .7; --l1: rgb(0 0 0 / .25)  } /* back */
.tree > .box > p:nth-child(3) { --ry: -90deg; --l2: .5; --l1: rgb(0 0 0 / .125) } /* left */
.tree > .box > p:nth-child(4) { --ry:  90deg; --l2: .5; --l1: rgb(255 255 255 / .125) } /* right */
.tree > .box > p:nth-child(5) { --rx:  90deg; --l2: .6; --l1: rgb(255 255 255 / .25) } /* top */
.tree > .box > p:nth-child(6) { --rx: -90deg; --l2: .6; --l1: rgb(0 0 0 / .25) } /* bottom */

/* front */
.tree > .box > p:nth-child(1) { transform-origin: left; transition: transform 500ms ease; cursor: pointer } 
.tree > .box:focus > p:nth-child(1){ transform: var(--transform) rotateY(-90deg) }
.tree > .box > p:nth-child(1)::after{ 
  content: counter(days);
  grid-area: 1/1;
  place-self: center;
  
  display: grid;
  place-items: center;
  width: 5vmin;
  aspect-ratio: 1;
  border-radius: 50%;
  background-color: var(--wrap);

  font-size: 2vmin;
  font-family: system-ui, sans-serif;
  color: var(--color);
  font-weight: bold;
}

/* wrappings */
.tree > .box:nth-child(3n + 1){ --wrap: green; --ribbon: red;   --color: gold }
.tree > .box:nth-child(3n + 2){ --wrap: red;   --ribbon: gold;  --color: gold }
.tree > .box:nth-child(3n + 3){ --wrap: gold;  --ribbon: green; --color: red  }

/* inside sides*/
.tree > .box > p::before { 
  content: ""; 
  grid-area: 1/1; 
  background-color: var(--wrap); 
  background-image: linear-gradient(rgb(0 0 0 / var(--l2, .25)) 105%, transparent);
  transform: translateZ(-.1px)
}

/* content */
.tree > .box::before {
  content: "";
  grid-area: 1/1;
  place-self: center;
  width: 75%;
  aspect-ratio: 1;
  background-image: var(--img);
  background-size: contain
}

/* animations */
.tree > .box:focus::before{ animation: rotateContent 3s linear infinite }
@keyframes rotateContent { to { transform: rotateY(360deg) } }

/* contents */
.tree > .box:nth-child(1) { --img: url(//repo.bfw.wiki/bfwrepo/images/gift/64/744/744546.png)}
.tree > .box:nth-child(2) { --img: url(//repo.bfw.wiki/bfwrepo/images/gift/64/6278/6278695.png)}
.tree > .box:nth-child(3) { --img: url(//repo.bfw.wiki/bfwrepo/images/gift/64/2299/2299172.png)}
.tree > .box:nth-child(4) { --img: url(//repo.bfw.wiki/bfwrepo/images/gift/64/892/892848.png)}
.tree > .box:nth-child(5) { --img: url(//repo.bfw.wiki/bfwrepo/images/gift/64/6278/6278637.png)}
.tree > .box:nth-child(6) { --img: url(//repo.bfw.wiki/bfwrepo/images/gift/64/3132/3132705.png)}
.tree > .box:nth-child(7) { --img: url(//repo.bfw.wiki/bfwrepo/images/gift/64/614/614114.png)}
.tree > .box:nth-child(8) { --img: url(//repo.bfw.wiki/bfwrepo/image.........完整代码请登录后点击上方下载按钮下载查看

网友评论0