当前位置: 首页 > news >正文

实现一个日语假名自测小程序html-css-js版

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>随机日语50音</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="container">
        <h1>随机日语50音</h1>
        <div id="character" class="character"></div>
        <button id="startButton">开始</button>
    </div>
    <script src="script.js"></script>
</body>
</html>
body {
  font-family: Arial, sans-serif;
  background-color: #f0f0f0;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  margin: 0;
}

.container {
  text-align: center;
  background-color: #fff;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.character {
  font-size: 72px;
  font-weight: bold;
  margin: 20px 0;
  color: #333;
}

button {
  padding: 10px 20px;
  font-size: 16px;
  background-color: #007bff;
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.3s;
}

button:hover {
  background-color: #0056b3;
}

button:disabled {
  background-color: #ccc;
  cursor: not-allowed;
}
// 平假名和片假名的列表
const hiragana = [
  "あ", "い", "う", "え", "お",
  "か", "き", "く", "け", "こ",
  "さ", "し", "す", "せ", "そ",
  "た", "ち", "つ", "て", "と",
  "な", "に", "ぬ", "ね", "の",
  "は", "ひ", "ふ", "へ", "ほ",
  "ま", "み", "む", "め", "も",
  "や", "ゆ", "よ",
  "ら", "り", "る", "れ", "ろ",
  "わ", "を", "ん"
];

const katakana = [
  "ア", "イ", "ウ", "エ", "オ",
  "カ", "キ", "ク", "ケ", "コ",
  "サ", "シ", "ス", "セ", "ソ",
  "タ", "チ", "ツ", "テ", "ト",
  "ナ", "ニ", "ヌ", "ネ", "ノ",
  "ハ", "ヒ", "フ", "ヘ", "ホ",
  "マ", "ミ", "ム", "メ", "モ",
  "ヤ", "ユ", "ヨ",
  "ラ", "リ", "ル", "レ", "ロ",
  "ワ", "ヲ", "ン"
];

const characterElement = document.getElementById("character");
const startButton = document.getElementById("startButton");
let animationInterval;
let animationDuration = 1000; // 动画持续时间 3 秒

// 随机选择一个字符
function getRandomCharacter() {
  const isHiragana = Math.random() < 0.5;
  const list = isHiragana ? hiragana : katakana;
  return list[Math.floor(Math.random() * list.length)];
}

// 开始动画
function startAnimation() {
  startButton.disabled = true; // 禁用按钮
  const startTime = Date.now();

  // 每 100 毫秒更新一次字符
  animationInterval = setInterval(() => {
      characterElement.textContent = getRandomCharacter();
  }, 100);

  // 3 秒后停止动画
  setTimeout(() => {
      clearInterval(animationInterval);
      startButton.disabled = false; // 启用按钮
  }, animationDuration);
}

// 绑定按钮点击事件
startButton.addEventListener("click", startAnimation);

相关文章:

  • XSS漏洞原理分类标签及关卡
  • 一般c++项目的目录结构
  • Ajax与Axios,以及Apifox的入门使用
  • 【AI-Coding】2025再实现简单的省市联动
  • NAT实验
  • 鸿蒙Flutter开发故事:不,你不需要鸿蒙化
  • Linux_进程概念(B)-环境变量进程地址空间【Linux】
  • 智能工厂能耗分析:Python驱动的高效能源管理
  • Python 编程题 第十二节:柠檬水找零、统计数字、合并排序数组、插入5、字符串置换
  • 内存管理(C++篇)
  • NLP高频面试题(八)——GPT三个版本的区别
  • 启明星辰春招面试题
  • 机器学习knnlearn2
  • coding ability 展开第五幕(二分查找算法)超详细!!!!
  • C语言中的指针
  • kvm虚拟机的基本使用
  • node-ddk, electron组件, 自定义本地文件协议,打开本地文件
  • C51 Proteus仿真实验22:按键发声
  • 云原生算力引擎:分布式推理的流体动力学
  • NVIDIA Dynamo源码编译
  • 全国多家健身房女性月卡延长,补足因月经期耽误的健身时间
  • 大外交丨3天拿下数万亿美元投资,特朗普在中东做经济“加法”和政治“减法”
  • 七猫征文大赛颁出112万奖金,非遗题材作品斩获金奖
  • 俄乌官员即将在土耳其会谈,外交部:支持俄乌开启直接对话
  • 年在沪纳税350亿人民币,这些全球头部企业表示“对上海承诺不会变”
  • 沧州低空经济起飞:飞行汽车开启千亿赛道,通用机场布局文旅体验