gsap实现与熊玩开关灯小游戏代码
代码语言:html
所属分类:游戏
代码描述:gsap实现与熊玩开关灯小游戏代码,小熊要睡觉,你拖动开关开灯,熊就很生气
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> * { box-sizing: border-box; } :root { --depth: 5vmin; --on: 0; --size: 25vmin; --bg: hsl(calc(200 - (var(--on) * 160)), calc((20 + (var(--on) * 50)) * 1%), calc((20 + (var(--on) * 60)) * 1%)); --cord: hsl(0, 0%, calc((60 - (var(--on) * 50)) * 1%)); --stroke: hsl(0, 0%, calc((60 - (var(--on) * 50)) * 1%)); --shine: hsla(0, 0%, 100%, calc(0.75 - (var(--on) * 0.5))); --cap: hsl(0, 0%, calc((40 + (var(--on) * 30)) * 1%)); --filament: hsl(45, calc(var(--on) * 80%), calc((25 + (var(--on) * 75)) * 1%)); } body { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); overflow: hidden; } label { position: absolute; opacity: 0.5; height: 100%; width: 100%; top: 0; left: 0; z-index: 2; } input { height: 0; width: 0; position: fixed; left: 100%; transform: scale(0); } .toggle { height: var(--size); width: var(--size); transform: translate(-50%, -100%); z-index: 2; position: absolute; top: 50%; left: 50%; transform: translate3d(-50%, -100%, calc(var(--depth) * 3)); } .toggle-scene { overflow: visible !important; width: 100%; position: absolute; } .toggle-scene__arm { display: none; } .toggle-scene__cord { stroke: var(--cord); cursor: move; } .toggle-scene__cord:nth-of-type(1) { display: none; } .toggle-scene__cord:nth-of-type(2), .toggle-scene__cord:nth-of-type(3), .toggle-scene__cord:nth-of-type(4), .toggle-scene__cord:nth-of-type(5) { display: none; } .toggle-scene__cord-end { stroke: var(--cord); fill: var(--cord); } .toggle-scene__dummy-cord { stroke-width: 6; stroke: var(--cord); } .bulb__filament { stroke: var(--filament); } .bulb__shine { stroke: var(--shine); } .bulb__flash { stroke: #f5e0a3; display: none; } .bulb__bulb { stroke: var(--stroke); fill: hsla(calc(180 - (95 * var(--on))), 80%, 80%, calc(0.1 + (0.4 * var(--on)))); } .bulb__cap { fill: var(--cap); } .bulb__cap-shine { fill: var(--shine); } .bulb__cap-outline { stroke: var(--stroke); } .bear { display: none; } .bear__fur { fill: #784421; } .bear__pad { fill: #deaa87; } .doorway { position: absolute; top: 50%; height: calc(var(--size) * 4); width: calc(var(--size) * 1.5); transform: translate(0, calc(var(--size) * -0.75)); left: calc(50% + (var(--size) * 0.5)); -webkit-clip-path: inset(0 0 0 -200%); clip-path: inset(0 0 0 -200%); } .doorway__opening { height: 100%; width: 100%; position: absolute; background: #1a1a1a; transform: translate3d(0, 0, calc(var(--depth) * -1)); } .bear { position: absolute; top: 10%; width: var(--size); } .door { --panel: hsl(30, 20%, calc(12% + (var(--on) * 40%))); height: 100%; position: absolute; width: 100%; transform-origin: 100% 50%; transform-style: preserve-3d; transform: rotateY(0deg); } .door__panel { width: 30%; height: 35%; position: absolute; border: 1vmin var(--panel) solid; top: 50%; left: 50%; transform: translate(-50%, -50%) translate(var(--x), var(--y)); } .door__panel:nth-of-type(1) { --x: -70%; --y: -70%; } .door__panel:nth-of-type(2) { --x: 70%; --y: -70%; } .door__panel:nth-of-type(3) { --x: -70%; --y: 70%; } .door__panel:nth-of-type(4) { --x: 70%; --y: 70%; } .door__handle { height: 4vmin; width: 4vmin; position: absolute; left: 10%; top: 50%; transform: translate3d(0, -50%, 1vmin); } .door__handle > div { position: absolute; height: 100%; width: 100%; background-color: hsl(45, 70%, calc((var(--lightness, 20%)) + (var(--on) * 40%))); } .door__handle > div:nth-of-type(1) { --lightness: 25%; } .door__handle > div:nth-of-type(2) { --lightness: 30%; transform: translate3d(0, 0, calc(var(--depth) * 1)); } .door__side { position: absolute; } .door__side:nth-of-type(1) { --lightness: 20%; height: 100%; width: 100%; transform: translate3d(0, 0, 0); z-index: 3; background-color: hsl(30, 20%, calc((var(--lightness, 20%)) + (var(--on) * 40%))); } .door__side:nth-of-type(2) { --lightness: 10%; height: 100%; width: 100%; transform: translate3d(0, 0, calc(var(--depth) * -1)); } .door__side { background-color: hsl(30, 20%, calc((var(--lightness, 20%)) + (var(--on) * 40%))); } .social-links { width: 44px; position: fixed; left: 1rem; bottom: 1rem; } .social-links > a + a { margin-top: 0.5rem; } .social-link { height: 44px; width: 44px; display: inline-block; } .social-link--jhey { --saturation: 49%; } .social-link--jhey img { transition: filter 0.2s; filter: saturate(var(--saturation)); } .social-link--jhey:hover { --saturation: 100%; } .social-link--twitter { --saturation: 49%; transition: fill 0.2s; } .social-link--twitter path { fill: hsl(203, var(--saturation), 53%); } .social-link--twitter:hover { --saturation: 89%; } .social-link img, .social-link svg { height: 100%; width: 100%; } </style> </head> <body > <div class="toggle"> <input id="light-mode" type="checkbox"/> <svg class="toggle-scene" xmlns="http://www.w3.org/2000/svg" preserveaspectratio="xMinYMin" viewBox="0 0 197.451 581.081"> <defs> <marker id="e" orient="auto" overflow="visible" refx="0" refy="0"> <path class="toggle-scene__cord-end" fill-rule="evenodd" stroke-width=".2666" d="M.98 0a1 1 0 11-2 0 1 1 0 012 0z"></path> </marker> <marker id="d" orient="auto" overflow="visible" refx="0" refy="0"> <path class="toggle-scene__cord-end" fill-rule="evenodd" stroke-width=".2666" d="M.98 0a1 1 0 11-2 0 1 1 0 012 0z"></path> </marker> <marker id="c" orient="auto" overflow="visible" refx="0" refy="0"> <path class="toggle-scene__cord-end" fill-rule="evenodd" stroke-width=".2666" d="M.98 0a1 1 0 11-2 0 1 1 0 012 0z"></path> </marker> <marker id="b" orient="auto" overflow="visible" refx="0" refy="0"> <path class="toggle-scene__cord-end" fill-rule="evenodd" stroke-width=".2666" d="M.98 0a1 1 0 11-2 0 1 1 0 012 0z"></path> </marker> <marker id="a" orient="auto" overflow="visible" refx="0" refy="0"> <path class="toggle-scene__cord-end" fill-rule="evenodd" stroke-width=".2666" d="M.98 0a1 1 0 11-2 0 1 1 0 012 0z"></path> </marker> <clippath id="scene" clippathunit="userSpaceOnUse"> <rect x="0" y="0" width="208.5" height="581.081"></rect> </clippath> <clippath id="g" clippathunits="userSpaceOnUse"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="4.677" d="M-774.546 827.629s12.917-13.473 29.203-13.412c16.53.062 29.203 13.412 29.203 13.412v53.6s-8.825 16-29.203 16c-21.674 0-29.203-16-29.203-16z"></path> </clippath> <clippath id="knuckles" clippathunits="userSpaceOnUse"> <path d="M-868.418 945.051c-4.188 73.011 78.255 53.244 150.216 52.941 82.387-.346 98.921-19.444 98.921-47.058 0-27.615-4.788-42.55-73.823-42.55-69.036 0-171.436-30.937-175.314 36.667z"></path> </clippath> </defs> <g clip-path="url(#scene)"> <g class="toggle-scene__arm toggle-scene__arm--main bear__arm bear__arm--back"> <g transform="translate(905.657 -597.025)" clip-path="url(#knuckles)"> <path class="bear__fur" d="M-868.418 945.051c-4.188 73.011 78.255 53.244 150.216 52.941 82.387-.346 98.921-19.444 98.921-47.058 0-27.615-4.788-42.55-73.823-42.55-69.036 0-171.436-30.937-175.314 36.667z"></path> <ellipse class="bear__pad" cx="804.83" cy="950.986" rx="29.911" ry="29.414" transform="scale(-1 1)"></ellipse> </g> </g> </g> <g class="toggle-scene__cords"> <path class="toggle-scene__cord" marker-end="url(#a)" fill="none" stroke-linecap="square" stroke-width="6" d="M123.228-28.56v150.493" transform="translate(-24.503 256.106)"></path> <path class="toggle-scene__cord" marker-end="url(#a)" fill="none" stroke-linecap="square" stroke-width="6" d="M123.228-28.59s28 8.131 28 19.506-18.667 13.005-28 19.507c-9.333 6.502-28 8.131-28 19.506s28 19.507 28 19.507" transform="translate(-24.503 256.106)"></path> <path class="toggle-scene__cord" marker-end="url(#a)" fill="none" stroke-linecap="square" stroke-width="6" d="M123.228-28.575s-20 16.871-20 28.468c0 11.597 13.333 18.978 20 28.468 6.667 9.489 20 16.87 20 28.467 0 11.597-20 28.468-20 28.468" transform="translate(-24.503 256.106)"></path> <path class="toggle-scene__cord" marker-end="url(#a)" fill="none" stroke-linecap="square" stroke-width="6" d="M123.228-28.569s16 20.623 16 32.782c0 12.16-10.667 21.855-16 32.782-5.333 10.928-16 20.623-16 32.782 0 12.16 16 32.782 16 32.782" transform="translate(-24.503 256.106)"></path> <path class="toggle-scene__cord" marker-end="url(#a)" fill="none" stroke-linecap="square" stroke-width="6" d="M123.228-28.563s-10 24.647-10 37.623c0 12.977 6.667 25.082 10 37.623 3.333 12.541 10 24.647 10 37.623 0 12.977-10 37.623-10 37.623" transform="translate(-24.503 256.106)"></path> <g class="line toggle-scene__dummy-cord"> <line marker-end="url(#a)" x1="98.7255" x2="98.7255" y1="250.5405" y2="380.5405"></line> </g> <circle class="toggle-scene__hit-spot" cx="98.7255" cy="380.5405" r="60" fill="transparent"></circle> </g> <g class="toggle-scene__bulb bulb" transform="translate(844.069 -645.213)"> <path class="bulb__cap" stroke-linecap="round" stroke-linejoin="round" stroke-width="4.677" d="M-774.546 827.629s12.917-13.473 29.203-13.412c16.53.062 29.203 13.412 29.203 13.412v53.6s-8.825 16-29.203 16c-21.674 0-29.203-16-29.203-16z"></path> <path class="bulb__cap-shine" d="M-778.379 802.873h25.512v118.409h-25.512z" clip-path="url(#g)" transform="matrix(.52452 0 0 .90177 -368.282 82.976)"></path> <path class="bulb__cap" stroke-linecap="round" stroke-linejoin="round" stroke-width="4" d="M-774.546 827.629s12.917-13.473 29.203-13.412c16.53.062 29.203 13.412 29.203 13.412v0s-8.439 10.115-28.817 10.115c-21.673 0-29.59-10.115-29.59-10.115z"></path> <path class="bulb__cap-outline" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="4.677" d="M-774.546 827.629s12.917-13.473 29.203-13.412c16.53.062 29.203 13.412 29.203 13.412v53.6s-8.825 16-29.203 16c-21.674 0-29.203-16-29.203-16z"></path> <g class="bulb__filament" fill="none" stroke-linecap="round" stroke-width="5"> <path d="M-752.914 823.875l-8.858-33.06"></path> <path d="M-737.772 823.875l8..........完整代码请登录后点击上方下载按钮下载查看
网友评论0