div+css实现纪念碑谷游戏场景效果代码
代码语言:html
所属分类:布局界面
代码描述:div+css实现纪念碑谷游戏场景效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> :root { --bs: 40px; } * { box-sizing: border-box; } body { display: grid; place-items: center; min-height: 100vh; background: linear-gradient(to bottom, #b4bba2, #2ab2aa); } .bird, .girl { position: absolute; width: 40px; height: 60px; z-index: 10; } .bird .inner, .girl .inner { display: flex; justify-content: center; position: absolute; top: 0; left: 0; width: 100%; height: 100%; } .bird .body, .girl .body { position: relative; height: 0; width: 0; border: 12px solid transparent; border-bottom: 26px solid #1c3765; } .bird .body::after, .girl .body::after { z-index: -1; content: ""; position: absolute; width: 24px; height: 10px; background: #1c3765; transform: translate(-50%, 21px); border-radius: 50%; box-shadow: 0 2px 1px 0 rgba(0, 0, 0, 0.05); } .bird .leg, .girl .leg { z-index: -1; position: absolute; height: 12px; width: 3px; background-color: #1c3765; border-radius: 4px; } .bird .leg::before, .girl .leg::before { position: absolute; content: ""; background-color: #1c3765; width: 5px; height: 4px; right: 0px; top: 10px; transform: rotate(-30deg); border-radius: 50%; } .bird .leg.l, .girl .leg.l { left: 13px; bottom: 9px; } .bird .leg.r, .girl .leg.r { left: 20px; bottom: 6px; } .bird .neck, .girl .neck { position: absolute; height: 5px; width: 5px; background: #1c3765; border-radius: 5px; top: 16px; } .bird .head, .girl .head { position: absolute; width: 18px; height: 18px; border-radius: 50%; background-color: #1c3765; top: 2px; } .bird { top: 160px; left: 270px; } .bird .head { transform: rotate(-25deg); } .bird .head .eye { top: 5px; left: 7px; position: absolute; width: 10px; height: 10px; border-radius: 50%; border: 2px solid white; z-index: 2; transform-origin: center; -webkit-animation: blink 10s linear infinite; animation: blink 10s linear infinite; } .bird .head::before, .bird .head::after { content: ""; position: absolute; width: 0; height: 0; border-top: 9px solid transparent; border-bottom: 9px solid transparent; border-right: 25px solid #1c3765; right: 9px; top: 0; transform-origin: right center; transform: rotate(0deg); } .bird .head::before { -webkit-animation: chirp-top 10s ease-in-out infinite; animation: chirp-top 10s ease-in-out infinite; } .bird .head::after { -webkit-animation: chirp-bot 10s ease-in-out infinite; animation: chirp-bot 10s ease-in-out infinite; } .bird .leg { transform-origin: top center; -webkit-animation: leg-swing 10s ease infinite; animation: leg-swing 10s ease infinite; } .bird .leg.r { -webkit-animation-delay: 0.1s; animation-delay: 0.1s; } .girl { --col: #d32c3b; top: 440px; left: 365px; } .girl .head { overflow: hidden; background-color: var(--col); } .girl .head::after { content: ""; position: absolute; width: 15px; height: 15px; background-color: white; border-radius: 10px; top: 5px; left: -2px; -webkit-animation: idle 8s ease-in-out 2s infinite; animation: idle 8s ease-in-out 2s infinite; } .girl .neck { background-color: var(--col); } .girl .body { border-bottom-color: var(--col); } .girl .body::after { background-color: var(--col); } .monument { position: relative; padding-top: 400px; height: 700px; width: 500px; overflow: hidden; } .grid { display: grid; grid-template-rows: repeat(10, var(--bs)); transform: rotateX(-55deg) rotateZ(45deg); } .row { display: grid; grid-template-columns: repeat(10, var(--bs)); } .block { --h: 0; transform: translate(calc(var(--h) * var(--bs) * -1), calc(var(--h) * var(--bs) * -1)); transition: transform 0.05s ease-in-out; background: #dcfff7; } .block.b { background: none; } .block::before, .block::after { content: ""; position: absolute; transition: all 0.05s ease-in-out; } .block::before { height: 100%; left: 100%; top: 0; background: linear-gradient(to right, #c48daf 0, #7480a8 200%); transform-origin: top left; transform: skew(0deg, 45deg); width: calc(var(--d) * var(--bs)); } .block::after { width: 100%; top: 100%; left: 0; background: linear-gradient(to bottom, #e9d1a3, #d7cca0); transform-origin: top left; transform: skew(45deg, 0deg); height: calc(var(--d) * var(--bs)); } .door { position: relative; } .door .door-top { position: absolute; width: 100%; height: 100%; --h: 2.2; --d: 0.2; background: #4e9be1; } .door .door-top::before { background: #6382b1; } .door .door-top::after { background: #5196df; } .door .door-left { --d: 2; --h: 2; position: absolute; width: 8%; height: 100%; } .door .door-right { --d: 2; --h: 2; position: absolute; width: 8%; height: 100%; right: 0; } .door .roof { position: absolute; transform: translate(-88px, -88px); border: 20px solid transparent; width: 0; height: 0; } .door .roof.left { border-bottom-color: #5196df; border-left-color: #5196df; } .door .roof.right { border-top-color: #6382b1; border-right-color: #6382b1; } .slab { --d: 1; } .ground { --d: 3; } .moveable { --d: 1; --x: 0; transform: translate(calc((var(--h) - var(--x)) * var(--bs) * -1), calc(var(--h) * var(--bs) * -1 )); background: #ffa4a0; background: repeating-radial-gradient(#ffa4a0, #ffa4a0 10px, #ff8c87 10px, #ff8c87 15px, #ffbcba 15px, #ffbcba 20px); } .moveable::before { background: #f28185; } .moveable::after { background: #ef9a9c; } .moveable.bot { --h: 1; } .stairs { background: none; transform: translate(calc(var(--h) * var(--bs) * -1), calc(var(--h) * var(--bs) * -1)); } .stairs .block:nth-of-type(1) { --h: calc(2 - 1 / 5 * 1); --d: calc(1 - (1 / 5)); } .stairs .block:nth-of-type(2) { --h: calc(2 - 1 / 5 * 2); --d: calc(1 - (1 / 5)); } .stairs .block:nth-of-type(3) { --h: calc(2 - 1 / 5 * 3); --d: calc(1 - (1 / 5)); } .stairs .block:nth-of-type(4) { --h: calc(2 - 1 / 5 * 4); --d: calc(1 - (1 / 5)); } .stairs .block:nth-of-type(5) { --h: calc(2 - 1 / 5 * 5); --d: calc(1 - (1 / 5)); } .stairs.left .block { width: 100%; height: 20%; } .stairs.right { display: flex; } .stairs.right .block { width: 20%; height: 100%; } input { cursor: pointer; position: absolute; z-index: 10; opacity: 0; } #lr { width: calc(3 * var(--bs)); transform: rotate(30deg) translate(30px, -170px); } #lr[data-value="0"] ~ .grid .moveable.top { --x: 0; } #lr[data-value="1"] ~ .grid .moveable.top { --x: 1; } #lr[data-value="2"] ~ .grid .moveable.top { --x: 2; z-index: -1; } #lr[data-value="3"] ~ .grid .moveable.top { --x: 3; z-index: -1; } #up { height: calc(2 * var(--bs)); transform: translate(320px, 155px); } #up[data-value="0"] ~ .grid .moveable.bot { --h: 1 ; } #up[data-value="1"] ~ .grid .moveable.bot { --h: 2; } #up[data-value="2"] ~ .grid .moveable.bot { --h: 3; } .run { -webkit-animation: move-1 2s linear infinite; animation: move-1 2s linear infinite; } .run .inner { -webkit-animation: run 0.15s ease-in-out infinite alternate; animation: run 0.15s ease-in-out infinite alternate; } .run .leg { transform-origin: top center; } .run .leg.l { -webkit-animation: kick 0.3s ease-out infinite alternate; animation: kick 0.3s ease-out infinite alternate; } .run .leg.r { animation: kick 0.3s ease-out infinite alternate-reverse; } @-webkit-keyframes move-1 { from { transform: translate(0, 0); } to { transform: translate(-140px, 90px); } } @keyframes move-1 { from { transform: translate(0, 0); } to { transform: translate(-140px, 90px); } } @-webkit-keyframes run { 0% { transform: translatey(0); } 100% { transform: translatey(-8px); } } @keyframes run { 0% { transform: translatey(0); } 100% { transform: translatey(-8px); } } @-webkit-keyframes kick { from { transform: rotatez(0deg); } to { transform: rotatez(-95deg); } } @keyframes kick { from { transform: rotatez(0deg); } to { transform: rotatez(-95deg); } } @-webkit-keyframes idle { 0%, 100% { transform: translate(0px, 0px); } 20% { transform: translate(-5px, -2px); } 40% { transform: translate(5px, 2px); } 60% { transform: translate(0px, 2px); } 80% { transform: translate(0, -2px); } } @keyframes idle { 0%, 100% { transform: translate(0px, 0px); } 20% { transform: translate(-5px, -2px); } 40% { transform: translate(5px, 2px); } 60% { transform: translate(0px, 2px); } 80% { transform: translate(0, -2px); } } @-webkit-keyframes blink { 38.5%, 41.5%, 28.5%, 31.5% { transform: scaley(1); } 40%, 30% { transform: scaley(0.1); } } @keyframes blink { 38.5%, 41.5%, 28.5%, 31.5% { transform: scaley(1); } 40%, 30% { transform: scaley(0.1); } } @-webkit-keyframes leg-swing { 0%, 80%, 84%, 88% { transform: rotate(0deg); } 82%, 86% { transform: rotate(30deg); } } @keyframes leg-swing { 0%, 80%, 84%, 88% { transform: rotate(0deg); } 82%, 86% { transform: rotate(30deg); } } @-webkit-keyframes chirp-top { 50%, 60% { border-top: 9px solid transparent; border-bottom: 9px solid transparent; transform: rotate(0); } 55% { b.........完整代码请登录后点击上方下载按钮下载查看
网友评论0