博客
关于我
JavaScript_打字游戏
阅读量:332 次
发布时间:2019-03-04

本文共 2304 字,大约阅读时间需要 7 分钟。

文章目录

效果图:

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

需求分析:

  1. 在char这个div里面显示要输入的字母,大写
  2. 在result这个div里面时时显示正确率,比如98%
  3. 给文档绑定按键事件
  4. 如果输入的内容和char里面一致,显示正确动画:animated zoomIn,并更换输入的字母
  5. 如果输入的内容和char里面不一致,显示错误动画:animated shake error
  6. 不管是正确还是错误都时时更新result里面的正确率

源代码:

  • HTML部分
A
请在按键上按下屏幕上显示的字母
  • css部分
  1. 为了实现一些特效,先创建一个animate.css文件,在封装一些动画效果放里面
/*animate.css*/.animated {     -webkit-animation-duration: 1s;  animation-duration: 1s;  -webkit-animation-fill-mode: both;  animation-fill-mode: both;}.animated.infinite {     -webkit-animation-iteration-count: infinite;  animation-iteration-count: infinite;}.animated.hinge {     -webkit-animation-duration: 2s;  animation-duration: 2s;}.animated.flipOutX,.animated.flipOutY,.animated.bounceIn,.animated.bounceOut {     -webkit-animation-duration: .75s;  animation-duration: .75s;}@-webkit-keyframes zoomIn {     from {       opacity: 0;    -webkit-transform: scale3d(.3, .3, .3);    transform: scale3d(.3, .3, .3);  }  50% {       opacity: 1;  }}@keyframes zoomIn {     from {       opacity: 0;    -webkit-transform: scale3d(.3, .3, .3);    transform: scale3d(.3, .3, .3);  }  50% {       opacity: 1;  }}.zoomIn {     -webkit-animation-name: zoomIn;  animation-name: zoomIn;}            .animated {     -webkit-animation-duration: 1s;  animation-duration: 1s;  -webkit-animation-fill-mode: both;  animation-fill-mode: both;}@-webkit-keyframes shake {     from, to {       -webkit-transform: translate3d(0, 0, 0);    transform: translate3d(0, 0, 0);  }  10%, 30%, 50%, 70%, 90% {       -webkit-transform: translate3d(-10px, 0, 0);    transform: translate3d(-10px, 0, 0);  }  20%, 40%, 60%, 80% {       -webkit-transform: translate3d(10px, 0, 0);    transform: translate3d(10px, 0, 0);  }}@keyframes shake {     from, to {       -webkit-transform: translate3d(0, 0, 0);    transform: translate3d(0, 0, 0);  }  10%, 30%, 50%, 70%, 90% {       -webkit-transform: translate3d(-10px, 0, 0);    transform: translate3d(-10px, 0, 0);  }  20%, 40%, 60%, 80% {       -webkit-transform: translate3d(10px, 0, 0);    transform: translate3d(10px, 0, 0);  }}.shake {     -webkit-animation-name: shake;  animation-name: shake;}
  1. css主体代码,无动画特效版
  • JavaScript部分
  1. 为了简化代码,先封装一些常用的自定义构造函数
  1. js主体部分,需要用到封装的函数,调用即可
  • 总代码
    
打字游戏
A
请在按键上按下屏幕上显示的字母

转载地址:http://yyxh.baihongyu.com/

你可能感兴趣的文章
Mysql学习第一课-mysql的定义及sql语句
查看>>
mysql学号的字符长度_MYSQL--2
查看>>
mysql安全模式: sql_safe_updates
查看>>
mysql安装,卸载,连接
查看>>
MySQL安装之没有配置向导
查看>>
mysql安装出现 conflicts with mysql*的解决办法
查看>>
mysql安装卡在最后一步解决方案(附带万能安装方案)
查看>>
mysql安装和启动命令小结
查看>>
Mysql安装教程(命令行)
查看>>
mysql安装版安装
查看>>
MySQL安装配置教程(非常详细),从零基础入门到精通,看完这一篇就够了
查看>>
mysql安装配置简介
查看>>
MySQL定义和变量赋值
查看>>
mysql定时任务事件清理单表数据
查看>>
MySQL定时器Events
查看>>
Mysql定时备份脚本
查看>>
mysql实战01|基础架构:一条SQL查询语句是如何执行的?
查看>>
Mysql实战之数据备份
查看>>
MySQL实战教程:从小白到大神的进阶之路!
查看>>
mysql实现成绩排名
查看>>