js+css实现经典带点击声效计算器代码

代码语言:html

所属分类:其他

代码描述:js+css实现经典带点击声效计算器代码

代码标签: js css 经典 点击 声效 计算器 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  


  
<style>
@import url("https://fonts.googleapis.com/css2?family=Abril+Fatface&display=swap");
/* Seven segment 
 *  from https://www.kraftilab.com/ 
 */
@font-face {
  font-family: "Seven Segment";
  src: url("//repo.bfw.wiki/bfwrepo/font/Seven+Segment.ttf");
}
@font-face {
  font-family: "Mona Sans";
  src: url("//repo.bfw.wiki/bfwrepo/font/Mona-Sans.woff2") format("woff2 supports variations"), url("//repo.bfw.wiki/bfwrepo/font/Mona-Sans.woff2") format("woff2-variations");
  font-weight: 100 1000;
}
@supports (background: paint(something)) {
  @layer properties {
    @property --base-hue {
      syntax: "<number>";
      inherits: true;
      initial-value: 0;
    }
    @property --gradient-start {
      syntax: "<color>";
      inherits: true;
      initial-value: 0;
    }
    @property --gradient-stop {
      syntax: "<color>";
      inherits: true;
      initial-value: 0;
    }
    @property --box-shadow-1 {
      syntax: "<color>";
      inherits: true;
      initial-value: 0;
    }
    @property --box-shadow-2 {
      syntax: "<color>";
      inherits: true;
      initial-value: 0;
    }
    @property --box-shadow-3 {
      syntax: "<color>";
      inherits: true;
      initial-value: 0;
    }
    @property --box-shadow-4 {
      syntax: "<color>";
      inherits: true;
      initial-value: 0;
    }
    @property --box-shadow-5 {
      syntax: "<color>";
      inherits: true;
      initial-value: 0;
    }
    @property --inner-background-start {
      syntax: "<color>";
      inherits: true;
      initial-value: 0;
    }
    @property --inner-background-stop {
      syntax: "<color>";
      inherits: true;
      initial-value: 0;
    }
    @property --inner-box-shadow-1 {
      syntax: "<color>";
      inherits: true;
      initial-value: 0;
    }
    @property --inner-box-shadow-2 {
      syntax: "<color>";
      inherits: true;
      initial-value: 0;
    }
    @property --inner-box-shadow-3 {
      syntax: "<color>";
      inherits: true;
      initial-value: 0;
    }
    @property --inner-box-shadow-4 {
      syntax: "<color>";
      inherits: true;
      initial-value: 0;
    }
    @property --screen-box-shadow-1 {
      syntax: "<color>";
      inherits: true;
      initial-value: 0;
    }
    @property --screen-box-shadow-2 {
      syntax: "<color>";
      inherits: true;
      initial-value: 0;
    }
  }
}
:root {
  --debug: 0;
  --bg-color: oklch(97.02% 0 0);
}

*,
*:before,
*:after {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  outline: calc(var(--debug) * 1px) dotted hsl(calc(var(--debug) * 10 * 1deg), 60%, 60%);
}

html,
body,
main {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background-color: #f5f5f5;
  background-image: conic-gradient(from 90deg at 1px 1px, transparent 90deg, rgba(0, 0, 0, 0.1) 0);
  background-size: 8vw 8vw;
  font-family: "Mona Sans", sans-serif;
  transition: --gradient-start 0.2s ease, --gradient-stop 0.2s ease, --box-shadow-1 0.2s ease, --box-shadow-2 0.2s ease, --box-shadow- 0.2s ease, --box-shadow-4 0.2s ease, --box-shadow-5 0.2s ease, --inner-background-start 0.2s ease, --inner-background-stop 0.2s ease, --inner-box-shadow-1 0.2s ease, --inner-box-shadow-2 0.2s ease, --inner-box-shadow-3 0.2s ease, --inner-box-shadow-4 0.2s ease, --screen-box-shadow-1 0.2s ease, --screen-box-shadow-2 0.2s ease;
}
body:before {
  content: "";
  display: block;
  position: absolute;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 50% 50%, transparent 50%, rgba(7, 8, 24, 0.4));
}

main {
  display: grid;
  place-items: center;
  grid-template-columns: repeat(1, 1fr);
  grid-template-rows: repeat(1, 1fr);
  align-items: center;
  justify-content: center;
}
main .calculator {
  transform: scale(1);
}

.calculator {
  --base-hue: 44;
  --base-saturation: 91;
  --base-lightness: 55;
  --gradient-start: hsl(
    var(--base-hue),
    calc(var(--base-saturation) * 1%),
    calc(var(--base-lightness) * 1%)
  );
  --gradient-stop: hsl(
    var(--base-hue),
    calc(calc(var(--base-saturation) - 6) * 1%),
    calc(calc(var(--base-lightness) + 13) * 1%)
  );
  --box-shadow-1: hsla(
    calc(var(--base-hue) - 10),
    16%,
    51%,
    80%
  );
  /* light gray */
  --box-shadow-2: hsla(
    calc(var(--base-hue) - 10),
    16%,
    51%,
    80%
  );
  /* light gray */
  --box-shadow-3: hsla(
    calc(var(--base-hue) - 10),
    34%,
    31%,
    80%
  );
  /* dark gray */
  --box-shadow-4: hsl(var(--base-hue), 100%, 89%);
  --box-shadow-5: hsla(calc(var(--base-hue) - 10), 92%, 48%, 80%);
  --inner-background-start: hsl(
    var(--base-hue),
    91%,
    calc(var(--base-lightness) * 1%)
  );
  --inner-background-stop: hsl(
    var(--base-hue),
    85%,
    calc(calc(var(--base-lightness)+13) * 1%)
  );
  --inner-box-shadow-1: hsl(
    var(--base-hue),
    100%,
    calc(calc(var(--base-lightness) + 26) * 1%)
  );
  --inner-box-shadow-2: hsl(
    calc(var(--base-hue) - 5),
    93%,
    calc(calc(var(--base-lightness) - 3) * 1%)
  );
  --inner-box-shadow-3: hsl(
    calc(var(--base-hue) - 20),
    88%,
    calc(calc(var(--base-lightness) - 27) * 1%)
  );
  --inner-box-shadow-4: hsl(
    var(--base-hue),
    100%,
    calc(calc(var(--base-lightness) + 34) * 1%)
  );
  --screen-background-start: hsl(30, 22%, 30%);
  --screen-background-stop: hsl(31, 22%, 34%);
  --screen-box-shadow-1: hsl(
    var(--base-hue) 83% calc(calc(var(--base-lightness) - 10) * 1%)
  );
  --screen-box-shadow-2: hsl(calc(var(--base-hue) - 10) 47% 22%);
  --screen-font-color: hsl(24, 64%, 28%);
  width: 286px;
  aspect-ratio: 57.2/85;
  background: linear-gradient(0.17deg, var(--gradient-start) 0.23%, var(--gradient-stop) 99.93%);
  box-shadow: -9px 14px 28px -7px var(--box-shadow-1), 9px 14px 28px -7px var(--box-shadow-2), 0px 22px 6px -10px var(--box-shadow-3), inset 0px 1px 1px var(--box-shadow-4), inset 0px -1px 2px var(--box-shadow-5);
  border-radius: 26px 26px 51px 51px;
  padding: 8px;
}
.calculator > div {
  display: flex;
  align-items: start;
  justify-content: center;
  flex-direction: column;
  padding: 14px;
  width: 100%;
  height: 100%;
  background: linear-gradient(0.17deg, var(--inner-background-start) 0.23%, ver(--inner-background-stop) 99.93%);
  box-shadow: 0px 2px 1px var(--inner-box-shadow-1), 0px -1px 2px var(--inner-box-shadow-2), inset 0px -1px 2px var(--inner-box-shadow-3), inset 0px 2px 2px var(--inner-box-shadow-4), inset 0 0 1px rgba(0, 0, 0, 0.15);
  border-radius: 19px 19px 43px 43px;
}
.calculator > div span:has(button) {
  display: flex;
  align-items: center;
  justify-content: center;
}
.calculator > div .screen {
  font-family: "Seven Segment", courier;
  width: 242px;
  height: 54px;
  background: linear-gradient(89.89deg, var(--screen-background-start) 0.08%, var(--screen-background-stop) 99.9%);
  box-shadow: 0px -1px 1px var(--screen-box-shadow-1), inset 0px 12px 4px -6px var(--screen-box-shadow-2), inset 0 -2px 1px color-mix(in srgb, var(--gradient-start), white 40%);
  border-radius: 8px;
  position: relative;
  font-style: normal;
  font-weight: 400;
  font-size: 37.1429px;
  font-feature-settings: "tnum";
  text-align: center;
  overflow: hidden;
}
@supports not (color: color-mix(in srgb, red, blue)) {
  .calculator > div .screen {
    box-shadow: 0px -1px 1px var(--screen-box-shadow-1), inset 0px 12px 4px -6px var(--screen-box-shadow-2), inset 0 -1px 1px rgba(255, 255, 255, 0.2);
  }
}
.calculator > div .screen:before {
  content: "000000000000";
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  filter: blur(1px);
  color: var(--screen-font-color);
  mix-blend-mode: hard-light;
  opacity: 0.5;
}
.calculator > div .screen .inner {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: end;
  padding: 0 9px;
  font-weight: bold;
  color: #1b0e07;
}
.calculator > div .screen .inner > span {
  position: relative;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.calculator > div .screen .inner > span:has(.dot) {
  width: 0;
}
.calculator > div .screen .dot {
  position: absolute;
  transform: translateX(0px) translateY(3px);
  font-size: 0.8em;
}
.calculator > div .controls {
  flex-grow: 1;
  margin-block: 8px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-row: repeat(2, 1fr);
  grid-gap: 10px;
  width: 100%;
}
.calculator > div .controls .functions {
  display: grid;
  grid-column-start: 1;
  grid-column-end: 5;
  grid-template-columns: repeat(4, 1fr);
  grid-gap: 10px;
  font-size: 12px;
}
.calculator > div .controls .functions span button {
  padding: 6px;
  width: 100%;
}
.calculator > div .controls .functions span button > span {
  transform: scale(1.8) translateY(1px);
}
.calculator > div .controls .functions span:first-of-type button {
  background: radial-gradient(87.74% 87.74% at 49.06% 94.34%, #f55404 0%, #ff6818 70.71%);
  box-shadow: 0px -1px 0px color-mix(in srgb, rgba(226, 141, 26, 0.2), hsl(var(--base-hue), 91%, 55%)), 0px 1px 1px color-mix(in srgb, rgba(179, 101, 0, 0.5), hsl(var(--base-hue), 91%, 55%)), 0px calc(var(--btn-clicked) * 1.2 * 1px) calc(var(--btn-clicked) * 1px) -2px color-mix(in srgb, #dc8211, hsl(var(--base-hue), 91%, 55%)), inset 0px -1px 0px #bb3203, inset -2px 2px 1px #ff8936;
  color: #8f1c02;
}
@supports not (color: color-mix(in srgb, red, blue)) {
  .calculator > div .controls .functions span:first-of-type button {
    box-shadow: 0px -1px 0px rgba(0, 0, 0, 0.3), 0px 1px 1px rgba(0, 0, 0, 0.3), 0px calc(var(--btn-clicked) * 1.2 * 1px) calc(var(--btn-clicked) * 1px) -2px rgba(0, 0, 0, 0.3), inset 0px -1px 0px #bb3203, inset -2px 2px 1px #ff8936;
  }
}
.calculator > div .controls .functions span:nth-child(odd) button {
  border-radius: 100px 63px 63px 100px;
}
.calculator > div .controls .functions span:nth-child(even) button {
  border-radius: 63px 100px 100px 63px;
}
.calculator > div .controls .numbers {
  display: grid;
  grid-column-start: 1;
  grid-column-end: 4;
  grid-template-columns: repeat(3, 1fr);
  grid-gap: 10px;
  font-family: "Abril Fatface", papyrus;
  font-size: 24px;
}
.calculator > div .controls .numbers span:nth-last-child(2) {
  grid-column-start: 1;
  grid-column-end: 3;
}
.calculator > div .controls .numbers span:nth-last-child(2) button {
  height: 100%;
  aspect-ratio: unset;
}
.calculator > div .controls .numbers button {
  width: 100%;
  aspect-ratio: 1/1;
}
.calculator > div .controls .elementary {
  display: grid;
  grid-template-rows: repeat(4, 1fr);
  grid-gap: 10px;
  font-size: 42px;
}
.calculator > div .controls .elementary > span:last-of-type {
  grid-row-start: 3;
  grid-row-end: 5;
}
.calculator > div .controls .elementary > span:last-of-type button {
  height: 100%;
}
.calculator button {
  --btn-clicked: 4;
  all: unset;
  cursor: pointer;
  background: radial-gradient(87.74% 87.74% at 49.06% 94.34%, #ffffff 0%, #e5e3e1 100%);
  box-shadow: 0px -1px 0px hsl(var(--base-hue), 50%, 50%), 0px 1px 1px color-mix(in hsl, var(--gradient-start), rgba(0, 0, 0, 0.5)), 0px calc(var(--btn-clicked) * 1.2 * 1px) calc(var(--btn-clicked) * 1px) -2px hsl(var(--base-hue), 50%, 45%), inset 0px -1px 0px #e9dfd5, inset -2px 2px 1px rgba(255, 255, 255, 0.7);
  width: 100%;
  padding: 2px;
  text-align: center;
  border-radius: 100000px;
  color: #b0b0a4;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.calculator button:before, .calculator button:after {
  content: attr(data-value);
  color: rgba(255, 255, 255, 0.2);
  position: absolute;
}
.calculator button:before {
  t.........完整代码请登录后点击上方下载按钮下载查看

网友评论0