js+css实现键盘立体可视化数字滚动页面翻转动画效果代码
代码语言:html
所属分类:加载滚动
代码描述:js+css实现键盘立体可视化数字滚动页面翻转动画效果代码
代码标签: js css 键盘 立体 可视化 数字 滚动 页面 翻转 动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> @property --rotate-x { syntax: "<angle>"; inherits: true; initial-value: 0deg; } @property --scene-rotation { syntax: "<angle>"; inherits: true; initial-value: 0deg; } @property --key-color { syntax: "<color>"; inherits: true; initial-value: transparent; } @property --foo { syntax: "<number>"; inherits: true; initial-value: 0; } :root { --color-primary: #5c4293; --color-secondary: #dd6058; --color-tertiary: #cfa469; --color-quaternary: #27235a; --color-surface: black; --key-depth: 4rem; --key-width: 4rem; --key-height: 5rem; --key-height-delta: 0rem; --key-color: rgba(255, 255, 255, 0.6); } body { color: var(--color-primary); background: url("//repo.bfw.wiki/bfwrepo/image/6701d58fdb581.png") center center no-repeat, #1f1f20; background-size: cover; background-attachment: fixed; margin: 0; font-family: "Road Rage", "Helvetica Neue", Roboto, "sans-serif"; } body:after { height: 100dvh; content: ""; position: fixed; background: url(//repo.bfw.wiki/bfwrepo/icon/5de90f964d501.png); mix-blend-mode: overlay; inset: 0; opacity: 0.5; pointer-events: none; filter: invert(1); z-index: 0; } a.labs-follow-me { left: 2rem; right: 2rem; bottom: 1rem; top: unset; text-align: center; } @-webkit-keyframes rotate360 { from { transform: rotate3d(1, 1, 1, 0deg); } to { transform: rotate3d(1, 1, 1, 360deg); } } @keyframes rotate360 { from { transform: rotate3d(1, 1, 1, 0deg); } to { transform: rotate3d(1, 1, 1, 360deg); } } @-webkit-keyframes scene-rotation { from { --scene-rotation: -5deg; } 50% { --scene-rotation: 12deg; } to { --scene-rotation: -5deg; } } @keyframes scene-rotation { from { --scene-rotation: -5deg; } 50% { --scene-rotation: 12deg; } to { --scene-rotation: -5deg; } } .scene { transform-style: preserve-3d; position: absolute; transition: transform 0.1s linear; transform: rotateX(calc(21deg - var(--rotate-x, 0deg))) rotateY(var(--scene-rotation)); } :root { -ms-scroll-snap-type: y mandatory; scroll-snap-type: y mandatory; } .views .item { font-size: 14rem; display: grid; place-items: center; scroll-snap-align: center; height: 100dvh; width: 100dvw; text-shadow: 0 0 1rem #d4bee8; color: white; -webkit-animation: show linear both; animation: show linear both; animation-timeline: --bubu; animation-range: entry-crossing 0% exit-crossing 100%; view-timeline: --bubu block; } .layers { position: fixed; z-index: 2; top: 50dvh; font-size: 25dvh; left: 0; right: 0; text-align: center; -webkit-animation: slide-up 0.01s linear; animation: slide-up 0.01s linear; animation-timeline: scroll(root block); --num-children: 6; --size-per-child: calc(100% / var(--num-children)); --half-size-per-child: calc(var(--size-per-child) / 2); --start-pos: calc(var(--half-size-per-child) * -1); --end-pos: calc(-100% + var(--half-size-per-child)); translate: 0 var(--start-pos); } .layers .item { height: 2rem; color: white; display: grid; place-items: center; transform-style: preserve-3d; transition: transform 0.6s linear; transform: translate3d(0, 30dvh, -400rem) perspective(27rem) scale(0.2); --foo: 0.8; --rotate-x: -50deg; } .layers .item.before { transform: translate3d(0, -30dvh, -400rem) perspective(27rem) scale(0.2); --rotate-x: -50deg; } .layers .item.active { --foo: 0; transform: translate3d(0, 0, 0rem) perspective(27rem) scale(1); --rotate-x: -1deg; } .layers .item.active .scene { -webkit-animation: 10s ease-in-out scene-rotation infinite; animation: 10s ease-in-out scene-rotation infinite; } @property --key-height-delta { syntax: "<length>"; initial-value: 0; inherits: true; } .container { width: var(--width); height: var(--width); transform-style: preserve-3d; position: relative; transform: rotate3d(1, 0, 0, -90deg); } .container .face { transform-style: preserve-3d; position: absolute; display: grid; place-items: center; font-size: 0.75rem; background: radial-gradient(circle at 50% -40%, var(--key-color), transparent 80%); border-radius: 0 0 var(--key-radius) var(--key-radius); opacity: 0.5; } .container .face.front { width: var(--width); height: calc(var(--height) - var(--key-height-delta)); transform: translate3d(0, var(--key-height-delta), var(--depth-half)); } .container .face.back { width: var(--width); height: calc(var(--height) - var(--key-height-delta)); transform: rotate3d(0, 1, 0, 180deg) translate3d(0, var(--key-height-delta), var(--depth-half)); } .container .face.left { width: var(--depth); height: calc(var(--height) - var(--key-height-delta)); transform: rotate3d(0, 1, 0, -90deg) translate3d(0, var(--key-height-delta), var(--width-half)); } .container .face.right { width: var(--depth); height: calc(var(--height) - var(--key-height-delta)); transform: rotate3d(0, 1, 0, 90deg) translate3d(0, var(--key-height-delta), var(--width-half)); } .container .face.top { width: var(--width); height: var(--depth); color: white; --key-color: rgba(255, 255, 255, 0.2); transform: rotate3d(1, 0, 0, 90deg) translate3d(0, 0, calc(var(--width-half) - var(--key-height-delta))); border-radius: var(--key-radius); border: 1px solid rgba(255, 255, 255, 0.13); opacity: 1; text-shadow: -1px -1px rgba(0, 0, 0, 0.3); background: radial-gradient(120% 120% at center, transparent, var(--key-color)); } labs-key { display: block; --key-radius: 0.5rem; --width: var(--key-width, 4rem); --depth: var(--key-depth, 4rem); --height: var(--key-height, 1rem); --width-half: calc(var(--width) / 2); --width-half-n: calc(var(--width) / -2); --depth-half: calc(var(--depth) / 2); --depth-half-n: calc(var(--depth) / -2); --width-n: calc(var(--width) * -1); --height-half: calc(var(--height) / 2); --height-half-n: calc(var(--height) / -2); position: relative; transform-style: preserve-3d; width: var(--width); height: var(--depth); cursor: pointer; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } labs-key.keypress { --key-height-delta: 0; -webkit-animation: keypress 0.1s ease forwards; animation: keypress 0.1s ease forwards; } @-webkit-keyframes keypress { from { --key-height-delta: 0rem; } to { --key-height-delta: calc(var(--key-height) * 0.3); } } @keyframes keypress { from { --key-height-delta: 0rem; } to { --key-height-delta: calc(var(--key-height) * 0.3); } } .keyboard { transform-style: preserve-3d; padding: 1rem 1rem 6rem 1rem; border-radius: 0.5rem; display: flex; gap: calc(var(--key-width) * 2 + 2rem); } .keyboard:after { transform-style: flat; background: #333; background: rgba(255, 255, 255, 0.08); background: linear-gradient(288deg, #e8d1a047, transparent); content: ""; z-index: -1; position: absolute; inset: 0; --c1: 31%; -webkit-mask-image: radial-gradient(82% 129% at 22% 40%, black var(--c1), transparent var(--c1)), radial-gradient(82% 129% at 78% 40%, black var(--c1), transparent var(--c1)), linear-gradient(to bottom, transparent 30%, black 30%), radial-gradient(126% 129% at 6% 118%, black var(--c1), transparent var(--c1)), radial-gradient(126% 129% at 95% 118%, black var(--c1), transparent var(--c1)), linear-gradient(to right, transparent 49%, black 49%, black 51%, transparent 51%); mask-image: radial-gradient(82% 129% at 22% 40%, black var(--c1), transparent var(--c1)), radial-gradient(82% 129% at 78% 40%, black var(--c1), transparent var(--c1)), linear-gradient(to bottom, transparent 30%, black 30%), radial-gradient(126% 129% at 6% 118%, black var(--c1), transparent var(--c1)), radial-gradient(126% 129% at 95% 118%, black var(--c1), transparent var(--c1)), linear-gradient(to right, transparent 49%, black 49%, black 51%, transparent 51%); -webkit-mask-composite: source-over, source-over, xor, source-over; mask-composite: add, add, exclude, add; -webkit-mask-size: 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 70%; mask-size: 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 70%; -webkit-mask-position: 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100%; mask-position: 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100%; -webkit-mask-repeat: no-repeat, no-repeat, no-repeat, no-repeat, no-repeat, no-repeat; mask-repeat: no-repeat, no-repeat, no-repeat, no-repeat, no-repeat, no-repeat; pointer-events: none; } .keyboard:before { pointer-events: none; transform-style: preserve-3d; background: rgba(255, 255, 255, 0.05); content: ""; position: absolute; transform: translate3d(0.45rem, 0.45rem, -0.45rem); inset: 0; --c1: 31%; -webkit-mask-image: radial-gradient(82% 129% at 22% 40%, black var(--c1), transparent var(--c1)), radial-gradient(82% 129% at 78% 40%, black var(--c1), transparent var(--c1)), linear-gradient(to bottom, transparent 30%, black 30%), radial-gradient(126% 129% at 6% 118%, black var(--c1), transparent var(--c1)), radial-gradient(126% 129% at 95% 118%, black var(--c1), transparent var(--c1)), linear-gradient(to right, transparent 49%, black 49%, black 51%, transparent 51%); mask-image: radial-gradient(82% 129% at 22% 40%, black var(--c1), transparent var(--c1)), radial-gradient(82% 129% at 78% 40%, black var(--c1), transparent var(--c1)), linear-gradient(to bottom, transparent 30%, black 30%), radial-gradient(126% 129% at 6% 118%, black var(--c1), transparent var(--c1)), radial-gradient(126% 129% at 95% 118%, black var(--c1), transparent var(--c1)), linear-gradient(to right, transparent 49%, black 49%, black 51%, transparent 51%); -webkit-mask-composite: source-over, source-over, xor, source-over; mask-composite: add, add, exclude, add; -webkit-mask-size: 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 70%; mask-size: 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 70%; -webkit-mask-position: 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100%; mask-position: 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100%; -webkit-mask-repeat: no-repeat, no-repeat, no-repeat, no-repeat, no-repeat, no-repeat; mask-repeat: no-repeat, no-repeat, no-repeat, no-repeat, no-repeat, no-repeat; } .left { transform-style: preserve-3d; display: grid; grid-template-columns: repeat(5, 1fr); grid-template-rows: repeat(3, auto); gap: 0.5rem; } .left > labs-key:nth-child(5n+1) { transform: translateY(calc(var(--key-depth))); } .left > labs-key:nth-child(5n+2) { transform: translateY(calc(var(--key-depth) / 2.5)); } .left > labs-key:nth-child(5n+4) { transform: translateY(calc(var(--key-depth) / 3)); } .left > labs-key:nth-child(5n+5) { transform: translateY(calc(var(--key-depth) / 2)); } .left > labs-key:nth-last-of-type(-2n + 2) { transform: translate3d(calc(var(--key-depth) / 2), calc(var(--key-depth) / 1.5), 0) rotateZ(10deg); } .left > labs-key:nth-last-of-type(-2n + 1) { transform: translate3d(calc(var(--key-depth) / 1.5), calc(var(--key-depth)), 0) rotateZ(20deg); } .right { transform-style: preserve-3d; display: grid; grid-template-columns: repeat(5, 1fr); grid-template-rows: repeat(3, auto); gap: 0.5rem; } .right > labs-key:nth-child(5n+1) { transform: translateY(calc(var(--key-depth) / 2)); } .right > labs-key:nth-child(5n+2) { transform: translateY(calc(var(--key-depth) / 3)); } .right > labs-key:nth-child(5n+4) { transform: translateY(calc(var(--key-depth) / 2.5)); } .right > labs-key:nth-child(5n+5) { transform: translateY(calc(var(--key-depth))); } .right > labs-key:nth-last-of-type(-2n + 2) { transform: translate3d(calc(var(--key-depth) / -1.5), calc(var(--key-depth)), 0) rotateZ(-20deg); } .right > labs-key:nth-last-of-type(-2n + 1) { transform: translate3d(calc(var(--key-depth) / -2), calc(var(--key-depth) / 1.5), 0) rotateZ(-10deg); } @media (width < 900px) { .layers { transform: scale(0.6); } .layers .item { visibility: hidden; } .layers .item:has(+ .active), .layers .item.active, .layers .item.active + .item { visibility: visible; } } </style> </head> <body translate="no"> <div id="views" class="views"> <div class="item">1</div> <div class="item">2</div> <div class="item">3</div> <div class="item">4</div> <div class="item">5</div> <div class="item">6</div> </div> <div id="layers" class="layers"> <div class="item active"> <div class="scene"> <div class="keyboard"> <div class="left"> <labs-key tag="&kp Q" style="--index:0" value="Q"></labs-key> <labs-key tag="&kp W" style="--index:0" value="W"></labs-key> <labs-key tag="&kp F" style="--index:0" value="F"></labs-key> <labs-key tag="&kp P" style="--index:0" value="P"></labs-key> <labs-key tag="&kp B" style="--index:0" value="B"></labs-key> <labs-key tag="&kp A" style="--index:1" value="A"></labs-key> <labs-key tag="&kp R" style="--index:1" value="R"></labs-key> <labs-key tag="&kp S" style="--index:1" value="S"></labs-key> <labs-key tag="&kp T" style="--index:1" value="T"></labs-key> <labs-key tag="&kp G" style="--index:1" value="G"></labs-key> <labs-key tag="&kp Z" style="--index:2" value="Z"></labs-key> <labs-key tag="&kp X" style="--index:2" value="X"></labs-key> <labs-key tag="&kp C" style="--index:2" value="C"></labs-key> <labs-key tag="&kp D" style="--index:2" value="D"></labs-key> <labs-key tag="&kp V" style="--index:2" value="V"></labs-key> <div></div> <div></div> <div></div> <labs-key tag="&mo NAV" style="--index:3" value="Mo(NAV)"></labs-key> <labs-key tag="&kp LSHIFT" style="--index:3" value="LSHIFT"></labs-key> </div> <div class="right"> <labs-key tag="&kp J" style="--index:0" value="J"></labs-key> <labs-key tag="&kp L" style="--index:0" value="L"></labs-key> <labs-key tag="&kp U" style="--index:0" value="U"></labs-key> <labs-key tag="&kp Y" style="--index:0" value="Y"></labs-key> <labs-key tag="&kp SQT" style="--index:0" value="SQT"></labs-key> <labs-key tag="&kp M" style="--index:1" value="M"></labs-key> <labs-key tag="&kp N" style="--index:1" value="N"></labs-key> <labs-key tag="&kp E" style="--index:1" value="E"></labs-key> <labs-key tag="&kp I" style="--index:1" value="I"></labs-key> <labs-key tag="&kp O" style="--index:1" value="O"></labs-key> <labs-key tag="&kp K" style="--index:2" value="K"></labs-key> <labs-key tag="&kp H" style="--index:2" value="H"></labs-key> <labs-key tag="&kp COMMA" style="--index:2" value="COMMA"></labs-key> <labs-key tag="&kp DOT" style="--index:2" value="DOT"></labs-key> <labs-key tag="&kp FSLH" style="--index:2" value="FSLH"></labs-key> <labs-key tag="&kp SPC" style="--index:3" value="SPC"></labs-key> <labs-key tag="&mo SYM" style="--index:3" value="Mo(SYM)"></labs-key> <div></div> <div></div> <div></div> </div> </div> </div> </div> <div class="item"> <div class="scene"> <div class="keyboard"> <div class="left"> <labs-key tag="&kp Q" style="--index:0" value="Q"></labs-key> <labs-key tag="&kp W" style="--index:0" value="W"></labs-key> <labs-key tag="&kp E" style="--index:0" value="E"></labs-key> <labs-key tag="&kp R" style="--index:0" value="R"></labs-key> <labs-key tag="&kp T" style="--index:0" value="T"></labs-key> <labs-key tag="&kp A" style="--index:1" value="A"></labs-key> <labs-key tag="&kp S" style="--index:1" value="S"></labs-key> <labs-key tag="&kp D" style="--index:1" value="D"></labs-key> <labs-key tag="&kp F" style="--index:1" value="F"></labs-key> <labs-key tag="&kp G" style="--index:1" value="G"></labs-key> <labs-key tag="&kp Z" style="--index:2" value="Z"></labs-key> <labs-key tag="&kp X" style="--index:2" value="X"></labs-key> <labs-key tag="&kp C" style="--index:2" value="C"></labs-key> <labs-key tag="&kp V" style="--index:2" value="V"></labs-key> <labs-key tag="&kp B" style="--index:2" value="B"></labs-key> <div></div> <div></div> <div></div> <labs-key tag="&mo NAV" style="--index:3" value="Mo(NAV)"></labs-key> <labs-key tag="&kp LSHIFT" style="--index:3" value="LSHIFT"></labs-key> </div> <div class="right"> <labs-key tag="&kp Y" style="--index:0" value="Y"></labs-key> <labs-key tag="&kp U" style="--index:0" value="U"></labs-key> <labs-key tag="&kp I" style="--index:0" value="I"></labs-key> <labs-key tag="&kp O" style="--index:0" value="O"></labs-key> <labs-key tag="&kp P" style="--index:0" value="P"></labs-key> <labs-key tag="&kp H" style="--index:1" value="H"></labs-key> <labs-key tag="&kp J" style="--index:1" value="J"></labs-key> <labs-key tag="&kp K" style="--index:1" value="K"></labs-key> <labs-key tag="&kp L" style="--index:1" value="L"></labs-key> <labs-key tag="&kp SQT" style="--index:1" value="SQT"></labs-key> <labs-key tag="&kp N" style="--index:2" value="N"></labs-key> <labs-key tag="&kp M" style="--index:2" value="M"></labs-key> <labs-key tag="&kp COMMA" style="--index:2" value="COMMA"></labs-key> <labs-key tag="&kp DOT" style="--index:2" value="DOT"></labs-key> <labs-key tag="&kp FSLH" style="--index:2" value="FSLH"></labs-key> <labs-key tag="&kp SPC" style="--index:3" value="SPC"></labs-key> <labs-key tag="&mo SYM" style="--index:3" value="Mo(SYM)"></labs-key> <div></div> <div></div> <div></div> </div> </div> </div> </div> <div class="item"> <div class="scene">.........完整代码请登录后点击上方下载按钮下载查看
网友评论0