缓存动画
来源:互联网 发布:网络医疗项目 编辑:程序博客网 时间:2024/06/07 14:09
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>缓存动画的封装</title> <style> *{ margin: 0; padding: 0; } div{ width: 200px; height: 200px; position: absolute; background-color: blue; } </style> <script> window.onload=function(){ var btn=document.getElementsByTagName("button"); var div=document.getElementsByTagName("div")[0]; //为按钮绑定事件 btn[0].onclick=function(){ animate(div,200); } btn[1].onclick=function(){ animate(div,400); } //封装animate函数 function animate(ele,target){ //实用定时器前先清除定时器 clearInterval(ele.timer); //设置定时器 ele.timer=setInterval(function(){ //除以10是为了取得黄金比例,事先约定俗成的 //步长应该是越来越小的,缓动的算法。 var stept=(target-ele.offsetLeft)/10; stept=stept>0?Math.ceil(stept):Math.floor(stept); //目标位置=当前位置+步长 ele.style.left=ele.offsetLeft+stept+"px"; //用于判断什么时候清除定时器 if(Math.abs(target-ele.offsetLeft)<=Math.abs(stept)){ ele.style.left=target+"px"; setInterval(ele.timer); }; },30) } } </script></head><body><button>向前运动200</button><button>向前运动400</button><div></div></body></html>
阅读全文
0 0
- 缓存动画
- cocos2D 缓存动画
- OPENGL帧缓存和动画
- OpenGL帧缓存和动画
- OPENGL帧缓存和动画
- OPENGL帧缓存和动画
- OpenGL帧缓存和动画
- OpenGL帧缓存和动画
- cocos2d-x 动画缓存CCAnimationCache
- OPENGL帧缓存和动画
- 【iOS-Cocos2d游戏开发】精灵缓存和动画缓存
- cocos2d-x——使用动画缓存做动画
- cocos2d-x 利用缓存实现帧动画
- 属性动画与图片三级缓存
- 缓存与预加载技术(图片缓存CCSpriteFrameCache、动画缓存 CCAnimationCache、纹理缓存CCTextureCache、音乐音效SimpleAudioEngine)
- cocos2d-x——用精灵帧缓存创建动画
- [Android]异步加载图片,内存缓存,文件缓存,imageview显示图片时增加淡入淡出动画
- Animation创建动画两种方式和AnimationCache动画缓存调用
- 了解代理模式
- 【学术篇】NOIP2016 D1T3 luogu1850换教室
- python3实现最大子序列和的在线处理方法
- ICPC2017网络赛(北京)Minimum(线段树or树状数组区间最值维护)
- spring data jpa 复杂的查询
- 缓存动画
- Protobuf
- Batch Normalization: Accelerating Deep Network Training b y Reducing Internal Covariate Shift
- python的时间转换datetime和pd.to_datetime
- P1062 数列
- Android性能优化一点理解
- LNMP环境搭建
- Java学习笔记----基本数据类型
- Java 字符串常量池