纯css+div实现一个抓住光小游戏代码
代码语言:html
所属分类:游戏
代码描述:纯css+div实现一个抓住光小游戏代码,选择速度,然后开始,当小球运动到有光的位置时,按下go按钮,没有一句js,全部是css+div编写的。
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
@import url("https://fonts.googleapis.com/css?family=Raleway:400,700");
*, *::before, *::after {
padding: 0;
margin: 0 auto;
box-sizing: border-box;
}
body {
font-family: Raleway, sans-serif;
background-color: #000;
color: #006;
min-height: 100vh;
display: grid;
place-items: center;
perspective: 100vmin;
font-size: 4vmin;
overflow: hidden;
}
body *:not(:empty) {
transform-style: preserve-3d;
}
:root {
--duration: 2s;
}
button {
position: absolute;
left: 50%;
top: 50%;
width: 10em;
height: 10em;
}
input {
display: none;
}
label {
cursor: pointer;
}
#rb-init:checked ~ .scene {
--bulbAnimation: bulb-pre;
--bulbPlayState: running;
--btnClose: 0;
--startMenuDisplay: grid;
}
#rb-init:checked ~ .scene .winner {
-webkit-animation: none;
animation: none;
}
#rb-init:checked ~ .scene .btnText::after {
-webkit-animation: none;
animation: none;
}
#rb-start:checked ~ .scene {
--bulbAnimation: bulb;
--scene-rx: 60deg;
--preDelay: 60;
--bulbPlayState: running;
--btnDuration: 1s 1s;
--stopLabelDisplay: block;
--markOpacity: 1;
--winnerPlayState: running;
}
#rb-start:checked ~ .scene .btnText::before {
-webkit-animation: startingText 2s step-end forwards;
animation: startingText 2s step-end forwards;
}
@-webkit-keyframes startingText {
0% {
content: "Catch";
}
20% {
content: "That";
}
40% {
content: "Light!";
}
60% {
content: "";
}
80%, 100% {
content: "Go!";
}
}
@keyframes startingText {
0% {
content: "Catch";
}
20% {
content: "That";
}
40% {
content: "Light!";
}
60% {
content: "";
}
80%, 100% {
content: "Go!";
}
}
#rb-start:checked ~ .scene .label-stop {
-webkit-animation: labelEnter 2s step-end forwards;
animation: labelEnter 2s step-end forwards;
}
#rb-stop:checked ~ .scene {
--bulbAnimation: bulb;
--preDelay: 60;
--btnClose: 0.5;
--winnerOpacity: 1;
--winningTextOpacity: 1;
--initLabelDisplay: block;
}
#rb-stop:checked ~ .scene .label-init {
-webkit-animation: labelEnter 1.5s step-end forwards;
animation: labelEnter 1.5s step-end forwards;
}
#rb-stop:checked ~ .scene .btnText::before {
content: "Try again?";
transform: translateY(1em) scale(0.5);
}
@-webkit-keyframes labelEnter {
0% {
transform: translateZ(1em) translateX(100vw);
}
80%, 100% {
transform: translateZ(1em) translateX(0);
}
}
@keyframes labelEnter {
0% {
transform: translateZ(1em) translateX(100vw);
}
80%, 100% {
transform: translateZ(1em) translateX(0);
}
}
.scene {
position: relative;
transform: rotateX(var(--scene-rx, 0deg));
transition: transform 1s 1s;
}
.button {
position: absolute;
transform: translateZ(-0.5em);
}
.button i {
position: absolute;
inset: -6em;
background-color: hsl(180, 75%, var(--light, 75%));
border-radius: 50%;
transform: translateZ(calc(var(--tz) * var(--btnClose, 1)));
transition: transform var(--btnDuration, 0.5s);
pointer-events: none;
}
.button i:nth-child(1) {
--tz: 0.1em;
--light: 20%;
}
.button i:nth-child(2) {
--tz: 0.2em;
--light: 25%;
}
.button i:nth-child(3) {
--tz: 0.3em;
--light: 30%;
}
.button i:nth-child(4) {
--tz: 0.4em;
--light: 35%;
}
.button i:nth-child(5) {
--tz: 0.5em;
--light: 40%;
}
.button i:nth-child(6) {
--tz: 0.6em;
--light: 45%;
}
.button i:nth-child(7) {
--tz: 0.7em;
--light: 50%;
}
.button i:nth-child(8) {
--tz: 0.8em;
--light: 55%;
}
.button i:nth-child(9) {
--tz: 0.9em;
--light: 60%;
}
.button i:nth-child(10) {
--tz: 1em;
--light: 65%;
}
.button:active i {
--btnClose: 0.5;
transition: none;
}
.btnText {
box-shadow: 0 0 2em #fff8 inset;
color: #004;
}
.btnText::before {
content: "";
position: absolute;
inset: 0;
display: grid;
place-items: center;
font-size: 2em;
}
.btnText::after {
content: "";
position: absolute;
inset: 0;
display: grid;
place-items: center;
font-size: 2em;
opacity: var(--winningTextOpacity, 0);
-webkit-animation: winnerText var(--duration) infinite step-end var(--winnerPlayState, paused);
animation: winnerText var(--duration) infinite step-end var(--winnerPlayState, paused);
}
@-webkit-keyframes winnerText {
0% {
content: "AMAZING!";
}
1.666%, 98.333% {
content: "Almost...";
}
3.333% {
content: "Missed :(";
}
}
@keyframes winnerText {
0% {
content: "AMAZING!";
}
1.666%, 98.333% {
content: "Almost...";
}
3.333% {
content: "Missed :(";
}
}
#rb-speed1:checked ~ .scene {
--duration: 5s;
}
#rb-speed2:checked ~ .scene {
--duration: 4s;
}
#rb-speed3:checked ~ .scene {
--duration: 3s;
}
#rb-speed4:checked ~ .scene {
--duration: 2s;
}
#rb-speed5:checked ~ .scene {
--duration: 1s;
}
#rb-speed1:checked ~ .scene .speeds label:nth-child(1),
#rb-speed2:checked ~ .scene .speeds label:nth-child(2),
#rb-speed3:checked ~ .scene .speeds label:nth-child(3),
#rb-speed4:checked ~ .scene .speeds label:nth-child(4),
#rb-speed5:checked ~ .scene .speeds label:nth-child(5) {
--color: green;
}
.startMenu {
display: var(--startMenuDisplay, none);
place-items: center;
position: absolute;
inset: -4em -6em;
transform: translateZ(1em);
}
.startMenu .speeds {
display: flex;
gap: 1em;
}
.startMenu .speeds label {
border-bottom: 3px solid var(--color, transparent);
}
.startMenu .speeds svg {
height: 1em;
fill: var(--color, maroon);
}
.startMenu .label-start {
border: 2px outset #600;
padding: 0.5em;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.startMenu .label-start:active {
border-style: inset;
}
.label-stop {
position: absolute;
inset: -6em;
border-radius: 50%;
transform: translateZ(1em) translateX(100vw);
display: var(--stopLabelDisplay, none);
}
.label-init {
position: absolute;
inset: -6em;
border-radius: 50%;
transform: translateZ(1em) translateX(100vw);
display: var(--initLabelDisplay, none);
}
.winner {
position: absolute;
-webkit-animation: winner var(--duration) infinite steps(60, end) var(--winnerPlayState, paused);
animation: winner var(--duration) infinite steps(60, end) var(--winnerPlayState, paused);
}
@-webkit-keyframes winner {
from {
transform: rotate(0deg) translateY(10em);
}
to {
transform: rotate(360deg) translateY(10em);
}
}
@keyframes winner {
from {
transform: rotate(0deg) translateY(10em);
}
to {
transform: rotate(360deg) translateY(10em);
}
}
.winner::after {
content: "";
position:.........完整代码请登录后点击上方下载按钮下载查看
网友评论0