没有引入deferred机制,其余流程都有了

//创建动画缓动对象 //

function Tween(value, prop, animation) {this.elem    = animation.elem;this.prop    = prop;this.easing  = "swing"; //动画缓动算法this.options = animation.options;//获取初始值this.start   = this.now = this.get();//动画最终值this.end     = value;//单位this.unit    = "px"
}function getStyles(elem) {return elem.ownerDocument.defaultView.getComputedStyle(elem, null);
};function swing(p) {return 0.5 - Math.cos(p * Math.PI) / 2;
}Tween.prototype = {//获取元素的当前属性get: function() {var computed = getStyles(this.elem);var ret = computed.getPropertyValue(this.prop) || computed[this.prop];return parseFloat(ret);},//运行动画
    run:function(percent){var eased//根据缓动算法改变percentthis.pos = eased = swing(percent);//获取具体的改变坐标值this.now = (this.end - this.start) * eased + this.start;//最终改变坐标this.elem.style[this.prop] = this.now + "px";return this;}
}////
//动画类 //
////
function Animation(elem, properties, options){//动画对象var animation = {elem            : elem,props           : properties,originalOptions : options,options         : options,startTime       : Animation.fxNow || createFxNow(),//动画开始时间tweens          : [] //存放每个属性的缓动对象,用于动画
    }//生成属性对应的动画算法对象for (var k in properties) {// tweens保存每一个属性对应的缓动控制对象animation.tweens.push( new Tween(properties[k], k, animation) )}//动画状态var stopped;//动画的定时器调用包装器var tick = function() {if (stopped) {return false;}//动画时间算法var currentTime = Animation.fxNow || createFxNow//运动时间递减remaining = Math.max(0, animation.startTime + animation.options.duration - currentTime),temp = remaining / animation.options.duration || 0,percent = 1 - temp;var index = 0,length = animation.tweens.length;//执行动画改变for (; index < length; index++) {//percent改变值
            animation.tweens[index].run(percent);}//是否继续,还是停止if (percent <= 1 && length) {return remaining;} else {//停止return false;}}tick.elem = elem;tick.anim = animationAnimation.fx.timer(tick)
}    //创建开始时间
function createFxNow() {setTimeout(function() {Animation.fxNow = undefined;});return (Animation.fxNow = Date.now());
}//用于定时器调用
Animation.timers =[]Animation.fx = {//开始动画队列
    timer: function(timer) {Animation.timers.push(timer);if (timer()) {//开始执行动画
            Animation.fx.start();} else {Animation.timers.pop();}},//开始循环
    start: function() {if (!Animation.timerId) {Animation.timerId = setInterval(Animation.fx.tick, 13);}},//停止循环
    stop:function(){clearInterval(Animation.timerId);Animation.timerId = null;},//循环的的检测
    tick: function() {var timer,i = 0,timers = Animation.timers;Animation.fxNow = Date.now();for (; i < timers.length; i++) {timer = timers[i];if (!timer() && timers[i] === timer) {//如果完成了就删除这个动画timers.splice(i--, 1);}}if (!timers.length) {Animation.fx.stop();}Animation.fxNow = undefined;}
}

测试:

<!doctype html>

<button id="one">jQuery动画的模拟实现:left:50</button> <button id="two">jQuery动画的模拟实现:left:500</button><ul id="book" style="background:red;opacity:1;position: relative; left: 300px;width:200px;height:100px;display:inline;" data-mce-style="background: red; opacity: 1; position: relative; left: 300px; width: 200px; height: 100px; display: inline;"></ul><script type="mce-text/javascript"> var book = document.getElementById('book'); var $book = $('#book'); var i = 10 while(i){ $book.append("<li>11</li>") i--; } //创建动画缓动对象 // function Tween(value, prop, animation) { this.elem = animation.elem; this.prop = prop; this.easing = "swing"; //动画缓动算法 this.options = animation.options; //获取初始值 this.start = this.now = this.get(); //动画最终值 this.end = value; //单位 this.unit = "px" } function getStyles(elem) { return elem.ownerDocument.defaultView.getComputedStyle(elem, null); }; function swing(p) { return 0.5 - Math.cos(p * Math.PI) / 2; } Tween.prototype = { //获取元素的当前属性 get: function() { var computed = getStyles(this.elem); var ret = computed.getPropertyValue(this.prop) || computed[this.prop]; return parseFloat(ret); }, //运行动画 run:function(percent){ var eased //根据缓动算法改变percent this.pos = eased = swing(percent); //获取具体的改变坐标值 this.now = (this.end - this.start) * eased + this.start; //最终改变坐标 this.elem.style[this.prop] = this.now + "px"; return this; } } //动画类 // function Animation(elem, properties, options){ //动画对象 var animation = { elem : elem, props : properties, originalOptions : options, options : options, startTime : Animation.fxNow || createFxNow(),//动画开始时间 tweens : [] //存放每个属性的缓动对象,用于动画 } //生成属性对应的动画算法对象 for (var k in properties) { // tweens保存每一个属性对应的缓动控制对象 animation.tweens.push( new Tween(properties[k], k, animation) ) } //动画状态 var stopped; //动画的定时器调用包装器 var tick = function() { if (stopped) { return false; } //动画时间算法 var currentTime = Animation.fxNow || createFxNow //运动时间递减 remaining = Math.max(0, animation.startTime + animation.options.duration - currentTime), temp = remaining / animation.options.duration || 0, percent = 1 - temp; var index = 0, length = animation.tweens.length; //执行动画改变 for (; index < length; index++) { //percent改变值 animation.tweens[index].run(percent); } //是否继续,还是停止 if (percent <= 1 && length) { return remaining; } else { //停止 return false; } } tick.elem = elem; tick.anim = animation Animation.fx.timer(tick) } //创建开始时间 function createFxNow() { setTimeout(function() { Animation.fxNow = undefined; }); return (Animation.fxNow = Date.now()); } //用于定时器调用 Animation.timers =[] Animation.fx = { //开始动画队列 timer: function(timer) { Animation.timers.push(timer); if (timer()) { //开始执行动画 Animation.fx.start(); } else { Animation.timers.pop(); } }, //开始循环 start: function() { if (!Animation.timerId) { Animation.timerId = setInterval(Animation.fx.tick, 13); } }, //停止循环 stop:function(){ clearInterval(Animation.timerId); Animation.timerId = null; }, //循环的的检测 tick: function() { var timer, i = 0, timers = Animation.timers; Animation.fxNow = Date.now(); for (; i < timers.length; i++) { timer = timers[i]; if (!timer() && timers[i] === timer) { //如果完成了就删除这个动画 timers.splice(i--, 1); } } if (!timers.length) { Animation.fx.stop(); } Animation.fxNow = undefined; } } $("#one").click(function(){ Animation(book, { left: '50' }, { duration: 2000 }) }); $("#two").click(function() { Animation(book, { left: '500' }, { duration: 2000 }) }); </script>

jQuery动画的实现相关推荐

  1. js进阶 13-6 jquery动画效果相关常用函数有哪些

    js进阶 13-6 jquery动画效果相关常用函数有哪些 一.总结 一句话总结:animate(),stop(),finish(),delat()四个. 1.stop()方法的基本用法是什么(sto ...

  2. Java程序员从笨鸟到菜鸟之(九十一)跟我学jquery(七)jquery动画大体验

    本文来自:曹胜欢博客专栏.转载请注明出处:http://blog.csdn.net/csh624366188 最近一直感觉自己好忙,每天都浑浑噩噩的过着,转眼间,好像有好长时间没有更新笨鸟到菜鸟了.现 ...

  3. 从零开始学习jQuery (七) jQuery动画-让页面动起来!

    本系列文章导航 从零开始学习jQuery (一) 开天辟地入门篇 从零开始学习jQuery (二) 万能的选择器 从零开始学习jQuery (三) 管理jQuery包装集 从零开始学习jQuery ( ...

  4. JQuery-学习笔记05【高级——JQuery动画和遍历】

    Java后端 学习路线 笔记汇总表[黑马程序员] JQuery-学习笔记01[基础--JQuery基础]--[day01] JQuery-学习笔记02[基础--JQuery选择器] JQuery-学习 ...

  5. jQuery 动画效果

    1.基本效果 (1)隐藏 hide() hide(speed [,callback]) (2)显示 show() show(speed [,callback]) (3)交替显示隐藏 toggle()  ...

  6. jquery笔记一:下载安装、语法、选择器、遍历选择元素的方法、jQuery动画

    目前 jQuery 兼容于所有主流浏览器, 包括 IE 6!开发时常用 jquery.js,上线用 jquery.min.js. jq插件 目前jQuery有三个大版本: (1)1.x.x: 兼容ie ...

  7. jQuery框架学习第七天:jQuery动画–jQuery让页面动起来!

    jQuery框架学习第一天:开始认识jQuery jQuery框架学习第二天:jQuery中万能的选择器 jQuery框架学习第三天:如何管理jQuery包装集 jQuery框架学习第四天:使用jQu ...

  8. js进阶 13 jquery动画函数有哪些

    js进阶 13 jquery动画函数有哪些 一.总结 一句话总结: 二.jquery动画函数有哪些 原生JavaScript编写动画效果代码比较复杂,而且还需要考虑兼容性.通过jQuery,我们使用简 ...

  9. [原创]jQuery动画弹出窗体支持多种展现方式

    今天刚写的利用jQuery动画弹出窗体,支持了string.Ajax.iframe.controls四种展现方式,具体细节下面慢慢介绍,先看效果图. 动画效果 从哪个对象上触发的即从该对象开始逐渐向屏 ...

  10. jquery动画切换引擎插件 Velocity.js 学习01

    一.Velocity.js介绍 Velocity是一个jQuery插件,重新实现了$.animate() 来产生更高的性能(速度也比CSS动画库更快),而包括新的功能,以提高动画工作流程. Veloc ...

最新文章

  1. linux 支持7代cpu型号,win7最高支持几代cpu
  2. 自然语言处理一大步,应用Word2Vec模型学习单词向量表征
  3. sqlserver 中的GUID 全局唯一标识 -摘自网络
  4. SpringBoot 2 快速整合 | 统一异常处理
  5. Android开发的第一天
  6. 计算机网络(一)-- 物理层与数据链路层
  7. 配置静态路由和VLAN
  8. 英语期刊写作-通往国际学术舞台的阶梯第五章答案
  9. 【转载】python做图像的傅里叶变换——二维傅里叶变换
  10. 正高、正常高和大地高的区别
  11. 77. Combinations
  12. 寂静岭3java攻略_《寂静岭3》完整流程攻略
  13. python复杂背景抠图_Opencv实现抠图背景图替换功能
  14. 金蝶虚拟化客户端连不上服务器,金蝶kis客户端远程连接服务器
  15. WordCAT 一款功能强大、免费共享的Word文档计算机辅助翻译软件
  16. css图片横向压缩,【css样式生成 图片合并压缩工具】Sprite,你值得拥有
  17. 解决Windows开机后无启动项的问题
  18. python sphinx_Python Sphinx使用踩坑记录
  19. linux内核是压测,从应用到内核查接口超时(中) -枕边书
  20. DirectX11 Effect特效文件

热门文章

  1. 龙将加速浏览器_360安全浏览器正式进军政企市场 积极适配中国芯
  2. linux新漏洞,「漏洞通告」Linux Kernel 信息泄漏权限提升漏洞(CVE-2020-8835)
  3. php cgi启动报错,php编译安装,cgi启动,以及memcache扩展编译安装.
  4. 11年瑞纳手动挡值多少钱_1个本科学历,值多少钱?
  5. getmethodid( android/widget/toast ),Android功能实现-Go语言中文社区
  6. php全面记录日志_全面解读PHP框架的日志系统
  7. 诺基亚7 android 9,诺基亚7 Plus正式推送安卓9.0系统!
  8. 深入理解计算机操作系统(六)
  9. Python学习之路28-符合Python风格的对象
  10. http协议的状态码——400,401,403,404,500,502,503,301,302等常见网页错误代码