css实现三维立体数字骰子跟随鼠标旋转动画效果代码
代码语言:html
所属分类:三维
代码描述:css实现三维立体数字骰子跟随鼠标旋转动画效果代码
代码标签: css 三维 立体 数字 骰子 跟随 鼠标 旋转 动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> @import url("https://fonts.googleapis.com/css2?family=Fjalla+One&display=swap"); * { margin: 0; padding: 0; box-sizing: border-box; } body { display: grid; place-items: center; min-height: 100vh; background-image: radial-gradient(#4d4d4d, #0d0d0d); overflow: hidden; perspective: 1000px; font-family: "Fjalla One", sans-serif; } body .scene, body .scene * { transform-style: preserve-3d; } body .scene { position: relative; width: 70vw; height: 70vw; margin-top: -60%; transform: rotateX(-40deg) rotateY(0deg) scale3d(1, 1, 1); animation: rot 30s ease-in-out 2s infinite alternate; } @keyframes rot { to { transform: rotateX(0deg) rotateY(360deg) scale3d(1, 1, 1); } } body .scene::after { content: ""; position: absolute; width: 100%; height: 100%; left: 0; top: 0; z-index: -100; box-shadow: inset 0 0 7vw #000; background-color: #1a1a1a; background-image: repeating-linear-gradient(#0000 0% 50%, #0000 50% 100%), repeating-radial-gradient(circle, #0000 0% 50%, #2e2e2e 50% 100%); background-size: 100%, 2vw 2vw, 2vw 2vw; transform: rotateX(90deg) translateZ(calc(70vw / -2)) scale(1); border-radius: 50%; } body .scene .dices { position: relative; width: 100%; height: 100%; bottom: 0; transform: translateX(12vw); } body .scene .cube, body .scene .cube * { position: absolute; bottom: 0; } body .scene .cube .container { display: grid; place-items: center; font-size: 5vw; counter-reset: dice; } body .scene .cube .container div { counter-increment: dice; background-image: radial-gradient(circle, #0005 50%, #fff1 50% 55%, #0000 60% 100%); color: gray; text-shadow: -1px 1px 3px rgba(0, 0, 0, 0.5), 1px -1px 0 rgba(255, 255, 255, 0.9); } body .scene .cube .container div:nth-child(1)::after { content: counter(dice); } body .scene .cube .container div:nth-child(2)::after { content: counter(dice); } body .scene .cube .container div:nth-child(3)::after { content: counter(dice); } body .scene .cube .container div:nth-child(4)::after { content: counter(dice); } body .scene .cube .container div:nth-child(5)::after { content: counter(dice); } body .scene .cube .container div:nth-child(6)::after { content: counter(dice); } body .scene #dice-1 { width: 10vw; height: 10vw; transform: translate3d(7vw, -10vw, 0); animation: dice-1-rot 15s ease-in-out infinite alternate; } body .scene #dice-1 .container { position: relative; width: 100%; height: 100%; } body .scene #dice-1 .container * { position: absolute; bottom: 0; display: flex; justify-content: center; align-items: center; } body .scene #dice-1 .container .left { width: 10vw; height: 10vw; background-color: #8a2db8; transform-origin: left top; transform: rotateY(-90deg) translateX(-5vw); } body .scene #dice-1 .container .right { width: 10vw; height: 10vw; background-color: #8a2db8; transform-origin: left top; transform: rotateY(90deg) translateX(-5vw) translateZ(10vw); } body .scene #dice-1 .container .top { background-color: darkorchid; width: 10vw; height: 10vw; transform-origin: bottom left; transform: rotateX(90deg) translateY(5vw) translateZ(10vw); } body .scene #dice-1 .container .bottom { background-color: darkorchid; width: 10vw; height: 10vw; transform-origin: bottom left; transform: rotateX(-90deg) translateY(5vw); } body .scene #dice-1 .container .front { background-color: #712597; width: 10vw; height: 10vw; transform-origin: bottom left; transform: translateZ(5vw); } body .scene #dice-1 .container .back { background-color: #712597; width: 10vw; height: 10vw; transform-origin: center; transform: rotateY(180deg) translateZ(5vw); } @keyframes dice-1-rot { to { transform: translate3d(10vw, -5vw, 0) rotate3d(1, 0.5, 0.5, 360deg); } } body .scene #dice-2 { width: 10vw; height: 10vw; transform: translate3d(28vw, -10vw, 0); animation: dice-2-rot 15s ease-in-out infinite alternate-reverse; } body .scene #dice-2 .container { position: relative; width: 100%; height: 100%; } body .scene #dice-2 .container * { position: absolute; bottom: 0; display: flex; justify-content: center; align-items: center; } body .scene #dice-2 .container .left { width: 10vw; height: 10vw; background-color: #7c2020; transform-origin: left top; transform: rotateY(-90deg) translateX(-5vw); } body .scene #dice-2 .container .right { width: 10vw; height: 10vw; background-color: #7c2020; transform-origin: left top; transform: rotateY(90deg) translateX(-5vw) translateZ(10vw); } body .scene #dice-2 .container .top { background-color: #912525; width: 10vw; height: 10vw; transform-origin: bottom left; transform: rotateX(90deg) translateY(5vw) translateZ(10vw); } body .scene #dice-2 .container .bottom { background-color: #912525; width: 10vw; height: 10vw; transform-origin: bottom left; transform: rotateX(-90deg) translateY(5vw); } body .scene #dice-2 .container .front { background-color: #5c1717; width: 10vw; height: 10vw; transform-origin: bottom left; transform: translateZ(5vw); } body .scene #dice-2 .container .back { background-color: #5c1717; width: 10vw; height: 10vw; transform-origin: center; transform: rotateY(180deg) translateZ(5vw); } @keyframes dice-2-rot { to { transform: translate3d(25vw, -5vw, 0) rotate3d(1, 0.5, 0.5, 360deg); } } body .scene #dice-3 { width: 10vw; height: 10vw; transform: translate3d(30vw, 0, -18vw) rotateY(10deg); } body .scene #dice-3 .container { position: relative; width: 100%; height: 100%; } body .scene #dice-3 .container * { position: absolute; bottom: 0; display: flex; justify-content: center; align-items: center; } body .scene #dice-3 .container .left { width: 10vw; height: 10vw; background-color: #4d2673; transform-origin: left top; transform: rotateY(-90deg) translateX(-5vw); } body .scene #dice-3 .container .right { width: 10vw; height: 10vw; background-color: #4d2673; transform-origin: left top; transform: rotateY(90deg) translateX(-5vw) translateZ(10vw); } body .scene #dice-3 .container .top { background-color: #592d86; width: 10vw; height: 10vw; transform-origin: bottom left; transform: rotateX(90deg) translateY(5vw) translateZ(10vw); } body .scene #dice-3 .container .bottom { background-color: #592d86; width: 10vw; height: 10vw; transform-origin: bottom left; transform: rotateX(-90deg) translateY(5vw); } body .scene #dice-3 .container .front { background-color: #381c54; width: 10vw; height: 10vw; transform-origin: bottom left; transform: translateZ(5vw); } body .scene #dice-3 .container .back { background-color: #381c54; width: 10vw; height: 10vw; transform-origin: center; transform: rotateY(180deg) translateZ(5vw); } body .scene #dice-3 .container .bottom { box-shadow: 0 0 5vw 2vw #000a; } body .scene #dice-4 { width: 10vw; height: 10vw; transform: translate3d(5vw, 0, 19vw) rotateY(-10deg) rotateX(-90deg); } body .scene #dice-4 .container { position: relative; width: 100%; height: 100%; } body .scene #dice-4 .container * { position: absolute; bottom: 0; display: flex; justify-content: center; align-items: center; } body .scene #dice-4 .container .left { width: 10vw; height: 10vw; .........完整代码请登录后点击上方下载按钮下载查看
网友评论0