纯css+div实现一个抓住光小游戏代码

代码语言:html

所属分类:游戏

代码描述:纯css+div实现一个抓住光小游戏代码,选择速度,然后开始,当小球运动到有光的位置时,按下go按钮,没有一句js,全部是css+div编写的。

代码标签: 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%;
.........完整代码请登录后点击上方下载按钮下载查看

网友评论0