div+css实现齿轮搭建木拼图动画效果代码
代码语言:html
所属分类:动画
代码描述:div+css实现齿轮搭建木拼图动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> * { transform-style: preserve-3d; box-sizing: border-box; } body { margin: 0; padding: 0; width: 100vw; height: 100vh; overflow: hidden; display: flex; align-items: center; justify-content: center; perspective: 500vmin; background: radial-gradient(circle at 50% -10%, #201534, #fff0), radial-gradient(circle at 50% 110%, #201534, #101010); } body:before, body:after { content: "HOVER TO ROTATE SCENE"; font-family: Arial, Helvetica, serif; font-size: 12px; position: absolute; width: 100%; text-align: center; top: 20px; color: #fff4; z-index: -1; color: #3b265c; z-index: -1; text-shadow: 0px -1px 0 #0008, 0 1px 0 #fff3; } body:after { content: "CLICK & HOLD TO PAUSE"; top: inherit; bottom: 20px; } body:hover:before { color: #d1b6ff; text-shadow: 0px -1px 0 #0008, 0 1px 0 #fff3; } body:active:after { color: #d1b6ff; text-shadow: 0px -1px 0 #0008, 0 1px 0 #fff3; } .content { width: 80vmin; height: 80vmin; display: flex; align-items: center; justify-content: center; transform: rotateX(-165deg) rotateY(-25deg); transition: all 2s ease 0s; transform: rotateX(-17deg) rotateY(-25deg); transition: all 0.5s ease 0s; position: absolute; } .cuboid { --height: 10; --width: 10; --depth: 8; --hue: 100; --sat: 80%; height: calc(var(--height) * 1vmin); width: calc(var(--width) * 1vmin); position: absolute; animation: cube1 0.6s linear 0s infinite; transform: translate3d(0vmin, 0vmin, 0vmin); } .cuboid .side { position: absolute; top: 50%; left: 50%; height: 100%; width: 100%; border-radius: 1px; background: hsl(var(--hue), var(--sat), var(--lum)); } .cuboid .side:nth-of-type(1) { transform: translate3d(-50%, -50%, calc(var(--depth) * 0.5vmin)); --lum: 35%; } .cuboid .side:nth-of-type(2) { transform: translate3d(-50%, -50%, calc(var(--depth) * -0.5vmin)) rotateY(180deg); --lum: 25%; } .cuboid .side:nth-of-type(3) { width: calc(var(--depth) * 1vmin); transform: translate(-50%, -50%) rotateY(90deg) translate3d(0, 0, calc(var(--width) * 0.5vmin)); --lum: 45%; } .cuboid .side:nth-of-type(4) { width: calc(var(--depth) * 1vmin); transform: translate(-50%, -50%) rotateY(-90deg) translate3d(0, 0, calc(var(--width) * 0.5vmin)); --lum: 30%; } .cuboid .side:nth-of-type(5) { height: calc(var(--depth) * 1vmin); transform: translate(-50%, -50%) rotateX(90deg) translate3d(0, 0, calc(var(--height) * 0.5vmin)); --lum: 20%; } .cuboid .side:nth-of-type(6) { height: calc(var(--depth) * 1vmin); transform: translate(-50%, -50%) rotateX(-90deg) translate3d(0, 0, calc(var(--height) * 0.5vmin)); --lum: 40%; } div[class^="piece-"], div[class*="piece-"] { width: 20vmin; height: 50vmin; margin-right: 2vmin; } .cuboid.long { --width: 6; --height: 50; } .cuboid.square { --width: 8; --height: 15; left: 6vmin; } .piece-2 .cuboid.square + .cuboid.square { bottom: 0; } .piece-2 .cuboid.square + .cuboid.long { right: 0; } .piece-3 .cuboid { --hue: 200; } .piece-3 .cuboid.long + .cuboid.square { --width: 14; --height: 22.5; } .piece-3 .cuboid.square + .cuboid.square { --width: 8; --height: 15; bottom: 0; } .piece-3 .cuboid.square + .cuboid.long { --height: 21.5; bottom: 0; right: 0; } .piece-3 { animation: piece3 4s ease 1s, piece3end 1s ease 9s, piece3end 1s ease 11s reverse, piece3 4s ease 16s reverse, piece3 4s ease 21s, piece3end 1s ease 29s; animation-fill-mode: forwards; } @keyframes piece3 { 0% { transform: rotateX(0deg) rotateY(0deg) translate3d(0vmin, 0vmin, 0vmin); } 25% { transform: rotateX(90deg) rotateY(-90deg) translate3d(0vmin, 0vmin, 0vmin); } 50% { transform: rotateX(90deg) rotateY(-90deg) translate3d(0vmin, 30vmin, 0vmin); } 75% { transform: rotateX(90deg) rotateY(-90deg) translate3d(0vmin, 30vmin, 22vmin); } 100% { transform: rotateX(90deg) rotateY(-90deg) translate3d(0vmin, 6.5vmin, 22vmin); } } @keyframes piece3end { 0% { transform: rotateX(90deg) rotateY(-90deg) translate3d(0vmin, 6.5vmin, 22vmin); } 100% { transform: rotateX(90deg) rotateY(-90deg) translate3d(0vmin, 0vmin, 22vmin); } } .piece-1 .cuboid { --hue: 0; } .piece-1 .cuboid.square + .cuboid.square { bottom: 0; } .piece-1 .cuboid.square ~ .cuboid.long { --height: 21; right: 0; } .piece-1 .cuboid.long + .cuboid.long { bottom: 0; } .piece-1 { animation: piece1 4s ease 5s, piece1 4s ease 12s reverse, piece1 4s ease 25s; animation-fill-mode: forwards; } @keyframes piece1 { 0% { transform: rotateX(0deg) translate3d(0, 0, 0); } 25% { transform: rotateX(90deg) translate3d(0, 0, 30vmin); } 50% { transform: rotateX(90deg) translate3d(15vmin, 0vmin, 30vmin); } 75% { transform: rotateX(90deg) translate3d(22vmin, 0vmin, 30vmin) rotateZ(-90deg); } 100% { transform: rotateX(90deg) translate3d(22vmin, 0vmin, 0vmin) rotateZ(-90deg); } } .cam { width: 9.09vw; height: 100vh; z-index: 10; } .cam:nth-child(1):hover ~ .content { transform: rotateX(-17deg) rotateY(-150deg); } .cam:nth-child(2):hover ~ .content { transform: rotateX(-17deg) rotateY(-135deg); } .cam:nth-child(3):hover ~ .content { transform: rotateX(-17deg) rotateY(-105deg); } .cam:nth-child(4):hover ~ .content { transform: rotateX(-17deg) rotateY(-85deg); } .cam:nth-child(5):hover ~ .content { transform: rotateX(-17deg) rotateY(-55deg); } .cam:n.........完整代码请登录后点击上方下载按钮下载查看
网友评论0