5.10.2_动画计时器
来源:互联网 发布:初音未来捏脸数据 编辑:程序博客网 时间:2024/06/11 21:37
5.10.2_动画计时器
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>动画计时器</title> <style> body{ background: #fff; } #canvas{ background: #eee; } #controls{ position: absolute; left: 25px; top: 25px; } </style> </head> <body> <div id="controls"> <input id="startStopButton" type="button" value="开始" /> </div> <canvas id="canvas" width="1000" height="600"></canvas> </body> <!-- 秒表的构造函数 --> <script> StopWatch = function(){}; StopWatch.prototype = { startTime: 0, running: false, elapsed: undefined, //过去的时间 start:function(){ this.startTime = +new Date(); this.elapsed = undefined; this.running = true; }, stop:function(){ this.elapsed = (+new Date()) - this.startTime; this.running = false; }, getElapsedTime:function(){ if(this.running){ return (+new Date()) - this.startTime; }else{ return this.elapsed; } }, isRunning:function(){ return this.running; }, reset:function(){ this.elapsed = 0; } } AnimationTimer = function(duration){ this.duration = duration; } AnimationTimer.prototype ={ duration:undefined, stopwatch:new StopWatch(), start:function(){ this.stopwatch.start(); }, stop:function(){ this.stopwatch.stop(); }, getElapsedTime:function(){ var elapsedTime = this.stopwatch.getElapsedTime();// if(!this.stopwatch.running){// return undefined;// }else{ return elapsedTime;// } }, isRunning:function(){ return this.stopwatch.isRunning(); }, isOver:function(){ return this.stopwatch.getElapsedTime()>this.duration; } } </script> <script> var canvas = document.getElementById('canvas'), context = canvas.getContext('2d'), startStopButton = document.getElementById('startStopButton'), animationTimer = new AnimationTimer(5000); startStopButton.onclick = function(){ if(this.value == '开始'){ this.value = '结束'; animationTimer.start(); requestAnimationFrame(animate); }else{ this.value = '开始'; animationTimer.stop(); } } function animate(){ if(animationTimer.isRunning()&&!animationTimer.isOver()){ console.log('动画还在持续中,当前已进行了'+animationTimer.getElapsedTime()); requestAnimationFrame(animate); }else if(animationTimer.isOver()){ animationTimer.stop(); startStopButton.value = '开始'; console.log('自动结束了,时间为'+animationTimer.getElapsedTime()); }else{ console.log('手动停止了动画,停止时已运行动画时间为'+animationTimer.getElapsedTime()); } } </script></html>
阅读全文
0 0
- 5.10.2_动画计时器
- 动画 (计时器)
- 计时器动画测试
- 98_定时器,计时器
- android--(动画2_属性动画)
- JavaScript实现动画计时器代码!!!
- cocos2d_x_04_计时器_数据存储
- 286_实现计时器功能
- Android 动画-->灵动菜单、计时器动画、下拉展开动画
- WPF动画特效以及计时器和触发器
- ios--计时器示例:一闪一闪亮晶晶(动画)
- 简单的计时器动画实现-ValueAnimator
- ios-计时器示范:一闪一闪View(动画效果)
- [VB.NET源码]6_计时器控件
- 进阶_计时器(Handler+Thread实现)_150503
- 进阶_计时器(postDelayed实现)_150503
- 进阶_计时器(Handler+TimerTask实现)_150503
- 安卓_动画_帧动画
- Android自定义View【实战教程】6⃣️---深入理解 Android 中的 Matrix
- centos6.8打开关闭端口
- -九个问题从入门到熟悉HTTPS
- 泛型的笔记
- No module named skimage.io的解决方法
- 5.10.2_动画计时器
- asp.net六大对象
- 判断进程是否存在,是否被杀死了
- LineFromChar每次获取的都是edit上次所在的位置
- 第七届蓝桥杯大赛个人赛决赛(软件类C语言B组)第一题:一步之遥
- java校验API(Hibernate Validator)
- PL/SQL高级编程
- Mac OS X 配置 Apache+Mysql+PHP 详细教程
- 微信小程序开发—(十四)表单组件1