js实现一个数字运算测验考试效果代码

代码语言:html

所属分类:其他

代码描述:js实现一个数字运算测验考试效果代码

代码标签: js 数字 运算 测验 考试

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


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

<head>

  <meta charset="UTF-8">
<link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/animate.4.1.1.css">
  
<style>
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

:root {
  --panel-bg: #f6f3f9;
}

::placeholder {
  color: #ccc;
}

:focus::placeholder {
  color: transparent;
}

button {
  appearance: none;
  border: 0;
  background: indigo;
  color: #fff;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
}

html,
html * {
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}

body {
  font-size: 16px;
  padding: 0;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, Helvetica Neue, sans-serif;
  background-color: var(--panel-bg);
}

main {
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  text-align: center;
  background: #fff;
}

.generators {
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
  padding: 1rem 0.75rem;
  border-top-left-radius: 1.5rem;
  border-top-right-radius: 1.5rem;
}

.generators-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
}

.generators-row:not(:last-child) {
  border-bottom: 1px solid #ddd;
  padding-bottom: 1rem;
  margin-bottom: 1rem;
}

.generators .icon {
  display: inline-block;
  width: 14px;
  margin-right: 4px;
  text-align: center;
}

.generators h3 {
  flex-grow: 1;
  text-align: left;
  margin: 0;
  font-weight: normal;
  font-size: 1rem;
}

.generators button.selected {
  background-color: #8900ed;
}

.quiz {
  margin: 3rem auto;
  font-family: monospace;
}

.quiz td {
  position: relative;
  padding: 0.3rem 0.2rem;
  white-space: nowrap;
}

.quiz-item {
  position: relative;
  align-items: center;
  text-align: right;
  font-size: 1.25rem;
}

.quiz-item-answer {
  width: 50px;
  padding: 4px 8px;
  border: 2px solid #ccc;
  border-radius: 4px;
  font-size: 1em;
  text-align: center;
}
.quiz-item-answer:focus {
  outline: 0;
  border-color: #2fa6ff;
}

.quiz-item[data-state="correct"] .quiz-item-answer {
  border-color: green;
}
.quiz-item[data-state="correct"] td:last-child:after {
  position: absolute;
  left: 100%;
  top: 0;
  display: flex;
  align-items: center;
  height: 100%;
  content: '✅';
  margin-left: 0.5rem;
  font-size: 1.6rem;
  animation: bounceIn;
  animation-duration: 0.7s;
}

.quiz-item[data-state="incorrect"] .quiz-item-answer {
  border-color: red;
}
.quiz-item[data-state="incorrect"] td:last-child:after {
  position: absolute;
  left: 100%;
  top: 0;
  height: 100%;
  display: flex;
  align-items: center;
  content: '🤔';
  margin-left: 0.5rem;
  font-size: 1.6rem;
}

.restart {
  visibility: hidden;
  margin: -1.5rem auto 1rem auto;
  font-size: 1.6rem;
  width: 60px;
  background: var(--panel-bg);
  color: indigo;
}

.quiz[data-state="completed"] + .restart {
  visibility: visible;
  opacity: 0;
  animation: bounceIn;
  animation-duration: 0.7s;
  animation-delay: 2s;
  animation-fill-mode: forwards;
}

@media only screen and (max-width: 360px) {
  html {
    font-size: 14px;
  }
}

@media only screen and (min-width: 600px) {
  body {
    background-color: #fff;
    padding: 4vh 2rem;
  }
  
  main {
    max-width: 380px;
    border: 1px solid var(--panel-bg);
    border-radius: 1.5rem;
    box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
  }

  .generators {
    border-radius: 1.4rem;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
  }
}
</style>



</head>

<body >
  <main>
  <h1>🧑‍🎓 Math Quiz 📚</h1>

  <table class="quiz"></table>
  
  <button class="restart">↺</button>

  <h2>Questions 👨‍🏫</h2>
  <div class="generators">
    <div class="generators-row">
      <h3><span class="icon">+</span>Addition</h3>
      <button data-qid="a1-5" data-operator="+" data-min="1" data-max="5">1-5</button>
      <button data-qid="a1-10" data-operator="+" data-min="1" data-max="10">1-10</button>
      <button data-qid="a1-50" data-operator="+" data-min="1" data-max="50">1-50</button>
      <button data-qid="a1-100" data-operator="+" data-min="1" data-max="100">1-100</button>
    </div>
    <div class="generators-row">
      <h3><span class="icon">-</span>Subtraction</h3>
      <button data-qid="s1-5" data-operator="-" data-min="1" data-max="5">1-5</button>
      <button data-qid="s1-10" data-operator="-" data-min="1" data-max="10">1-10</button>
      <button data-qid="s1-50" data-operator="-" data-min="1" data-max="50">1-50</button>
      <button data-qid="s1-100" data-operator="-" data.........完整代码请登录后点击上方下载按钮下载查看

网友评论0