gsap+svg实现小熊气球漂浮击落小游戏代码
代码语言:html
所属分类:游戏
代码描述:gsap+svg实现小熊气球漂浮击落小游戏代码,看看你能击落多少个小熊气球。
代码标签: gsap svg 小熊 气球 漂浮 击落 小游戏 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
@import "normalize.css";
* {
box-sizing: border-box;
}
:root {
--digit: hsl(0 0% 100% / 0.8);
}
body {
display: grid;
min-height: 100vh;
place-items: center;
counter-reset: popped 0;
overflow: hidden;
background: hsl(210 80% 90%);
font-family: 'SF Pro Text', 'SF Pro Icons', 'AOS Icons', 'Helvetica Neue',
Helvetica, Arial, sans-serif, system-ui;
font-weight: bold;
}
@media(prefers-color-scheme: dark) {
body {
background: hsl(210 30% 15%);
}
}
.pop-counter {
font-size: 1.25rem;
font-weight: bold;
color: var(--digit);
font-family: sans-serif, system-ui;
display: flex;
gap: 0.5rem;
align-items: center;
padding: 0.5rem;
}
main [popover]:not(#results, #level0):popover-open {
counter-increment: popped 1;
}
main [popover]:not(#results) :checked {
counter-increment: popped 1;
}
.pops:after {
content: counter(popped);
font-size: 1.25rem;
color: transparent;
}
main:after {
content: counter(popped);
top: 1rem;
left: calc(50% + 2.5rem);
top: anchor(--status top);
right: anchor(--status center);
position: fixed;
font-size: 1.25rem;
font-weight: bold;
color: var(--digit);
font-family: sans-serif, system-ui;
display: flex;
gap: 0.5rem;
align-items: center;
padding: 0.5rem;
z-index: 2;
opacity: var(--playing, 0);
transition: opacity 0.2s;
}
[role=image] {
display: inline-block;
translate: -50% 0;
}
.dialog {
position: fixed;
top: 50%;
left: 50%;
translate: -50% -50%;
background: linear-gradient(hsl(0 0% 15%), hsl(0 0% 15%)) padding-box, linear-gradient(hsl(0 0% 35%), hsl(0 0% 0%)) border-box;
color: hsl(0 0% 100% / 0.8);
padding: 2rem;
display: grid;
place-items: center;
transition: transform 0.25s;
transform: translateY(calc(var(--hide, 0) * 100vh));
border: solid transparent 4px;
border-radius: 0.5rem;
width: 70ch;
max-width: 100%;
}
.dialog-bear {
width: 100%;
height: 100%;
}
.intro-bear {
height: 100%;
width: clamp(250px, 20vmin + 1rem, 30rem);
}
.dialog--intro {
display: grid;
grid-template-columns: auto 1fr;
}
.score:after {
content: "You popped "counter(popped)" balloons!";
font-size: 1.5rem;
}
.intro {
display: flex;
flex-direction: column;
flex: 1;
gap: 1rem;
}
.dialog button {
border: 4px solid white;
background: transparent;
padding: 1rem 2rem;
border-radius: 100px;
color: white;
font-weight: bold;
font-size: 1.25rem;
transition: background 0.2s;
cursor: pointer;
}
h1 {
font-size: 4rem;
color: white;
line-height: 1;
margin: 0;
}
.dialog p {
font-size: 1.25rem;
margin: 0;
font-weight: 300;
}
.dialog button:hover {
background: hsl(0 90% 50%);
}
.dialog--result {
display: grid;
gap: 1rem;
padding: 2rem 4rem;
}
.dialog--result h2 {
font-size: 3rem;
margin: 0;
}
#result:popover-open .dialog--result {
--hide: 0;
-webkit-animation: pop-up 0.25s both;
animation: pop-up 0.25s both;
}
@-webkit-keyframes pop-up {
from {
transform: translateY(100vh);
}
}
@keyframes pop-up {
from {
transform: translateY(100vh);
}
}
:root:has(#level0:popover-open) .dialog--intro {
--hide: 1;
}
[popover] {
inset: unset;
position: fixed;
height: 100vh;
width: 100vw;
inset: 0;
top: 0;
border: 0;
padding: 0;
overflow: hidden;
background: transparent;
}
.bear {
--hue: 280;
position: absolute;
top: 100%;
left: calc(var(--x, 0) * 1%);
width: calc(var(--size, 0) * 1%);
translate: -50% 0;
min-width: 48px;
aspect-ratio: 1;
transform: rotateY(calc(var(--flip, 0) * 180deg));
-webkit-animation: float calc(var(--speed) * 1s) calc(var(--delay) * 1s) infinite linear;
animation: float calc(var(--speed) * 1s) calc(var(--delay) * 1s) infinite linear;
}
.bear button {
background: transparent;
border: 0;
}
@-webkit-keyframes float {
to {
translate: -50% calc(-100vh - 600%);
}
}
@keyframes float {
to {
translate: -50% calc(-100vh - 600%);
}
}
.bear--golden .bear__fur {
fill: hsl(45 90% 70%);
}
.bear__balloon {
fill: hsl(var(--hue, 10) 80% 80% / var(--alpha, 0.65));
transition: fill 0.2s;
}
.bear__strap {
fill: hsl(var(--hue, 10) 100% 50%);
}
.bear [type=checkbox] {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border-width: 0;
}
.bear svg {
pointer-events: none;
position: absolute;
z-index: 2;
top: 0;
width: 254%;
left: 50%;
translate: -47.5% -9%;
}
.bear :is(button, label) {
width: 100%;
aspect-ratio: 1;
opacity: 1;
padding: 0;
border-radius: 50%;
display: block;
cursor: pointer;
position: absolute;
z-index: 2;
}
[popover]:has(~ [popover]:popover-open) .bear:has(button) .bear__content {
pointer-events: none;
-webkit-animation: drop 1s forwards, eliminate 1s steps(1, end) both;
animation: drop 1s forwards, eliminate 1s steps(1, end) both;
}
[popover]:has(~ [popover]:popover-open) .bear:has(button) .bear__balloon {
pointer-events: none;
-webkit-animation: pop 0.2s forwards;
animation: pop 0.2s forwards;
transform-box: fill-box;
transform-origin: 50% 50%;
}
.bear button {
border: 0;
}
.bear__content {
height: 100%;
width: 100%;
}
.bear:has(:checked) .bear__content {
pointer-events: none;
-webkit-animation: drop 1s forwards, eliminate 1s steps(1, end) both;
animation: drop 1s forwards, eliminate 1s steps(1, end) both;
}
.bear:has(:checked) .bear__balloon {
-webkit-animation: pop 0.2s forwards;
animation: pop 0.2s forwards;
transform-box: fill-box;
transform-origin: 50% 50%;
}
@-webkit-keyframes pop {
to {
scale: 1.5;
opacity: 0;
}
}
@keyframes pop {
to {
scale: 1.5;
opacity: 0;
}
}
@-webkit-keyframes drop {
to {
translate: 0% calc(100vh + 600%);
}
}
@keyframes drop {
to {
translate: 0% calc(100vh + 600%);
}
}
@-webkit-keyframes eliminate {
to {
opacity: 0;
}
}
@keyframes eliminate {
to {
opacity: 0;
}
}
.bear:has(:is(label, button):hover) {
--alpha: 1;
}
[popover]:has(+ [popover] + [popover]:popover-open) .bear {
opacity: 0;
-webkit-animation: none;
animation: none;
}
[id*=level]:has(+ [popover]:not(#result):popover-open) .bear:not(:has(:checked)):not(:has(button)) .bear__content {
-webkit-animation: fade-away.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0