博客
关于我
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 InnoDB存储引擎 —— 数据页
查看>>
Mysql InnoDB存储引擎中的checkpoint技术
查看>>
Mysql InnoDB存储引擎中缓冲池Buffer Pool、Redo Log、Bin Log、Undo Log、Channge Buffer
查看>>
MySQL InnoDB引擎的锁机制详解
查看>>
Mysql INNODB引擎行锁的3种算法 Record Lock Next-Key Lock Grap Lock
查看>>
mysql InnoDB数据存储引擎 的B+树索引原理
查看>>
mysql innodb通过使用mvcc来实现可重复读
查看>>
mysql insert update 同时执行_MySQL进阶三板斧(三)看清“触发器 (Trigger)”的真实面目...
查看>>
mysql interval显示条件值_MySQL INTERVAL关键字可以使用哪些不同的单位值?
查看>>
Mysql join原理
查看>>
MySQL Join算法与调优白皮书(二)
查看>>
Mysql order by与limit混用陷阱
查看>>
Mysql order by与limit混用陷阱
查看>>
mysql order by多个字段排序
查看>>
MySQL Order By实现原理分析和Filesort优化
查看>>
mysql problems
查看>>
mysql replace first,MySQL中处理各种重复的一些方法
查看>>
MySQL replace函数替换字符串语句的用法(mysql字符串替换)
查看>>
mysql replace用法
查看>>
Mysql Row_Format 参数讲解
查看>>