博客
关于我
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/

你可能感兴趣的文章
Nginx学习总结(14)——Nginx配置参数详细说明与整理
查看>>
Nginx学习总结(15)—— 提升 Web 应用性能的十个步骤
查看>>
Nginx学习总结(1)——Nginx入门简介
查看>>
Nginx学习总结(2)——Nginx手机版和PC电脑版网站配置
查看>>
Nginx学习总结(3)——Nginx配置及应用场景之高级配置
查看>>
Nginx学习总结(4)——负载均衡session会话保持方法
查看>>
Nginx学习总结(5)——Nginx基本配置备忘
查看>>
Nginx学习总结(6)——Nginx + https + 免费SSL证书配置指南
查看>>
Nginx学习总结(7)——Nginx配置HTTPS 服务器
查看>>
Nginx学习总结(8)——Nginx服务器详解
查看>>
Nginx学习总结(9)——前端跨域问题解决
查看>>
nginx学习笔记
查看>>
nginx学习笔记001---Nginx的启动、停止与重启
查看>>
nginx学习笔记002---Nginx代理配置_案例1_实现了对前端代码的方向代理_并且配置了后端api接口的访问地址
查看>>
nginx学习笔记003---Nginx代理配置_注意,在Windows中路径要用/
查看>>
Nginx学习笔记(一) Nginx架构
查看>>
nginx学习路线
查看>>
Nginx安装
查看>>
Nginx安装SSL模块 nginx: the “ssl” parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx
查看>>
nginx安装stream模块配置tcp/udp端口转发
查看>>