js 动画封装
来源:互联网 发布:云南师范大学网络教学 编辑:程序博客网 时间:2024/05/29 10:00
/*------------------------------------------------------------------------------------ * 动画类 * @param {object} dom 执行动画的dom * @param {object} list css样式列表,如{marginLeft:'200px',width:'500px'} * @param {number} time 执行时间 * @param {string} tweenType 缓动类型 * @param {Function} callback 动画执行完毕后的回调函数------------------------------------------------------------------------------------*/window.requestAnimFrame = (function(){return window.requestAnimationFrame ||window.webkitRequestAnimationFrame ||window.mozRequestAnimationFrame ||window.oRequestAnimationFrame ||window.msRequestAnimationFrame ||function(/* function */ callback, /* DOMElement */ element){window.setTimeout(callback, 1000 / 60);};})();M.Animate = function(dom , list , time , tweenType ,callback){return new M.Animate.prototype.init( dom , list , time , tweenType ,callback );};M.Animate.prototype = {init:function(dom , list , time , tweenType ,callback){this.dom = dom;this.time = time || 300;this.preTime = 10;this.list = list;this.callback = callback;this.tweenType = tweenType || "easeInOut";this._d = Math.ceil( this.time / this.preTime );this._t=0;this._c = {};this._b = {};for(var k in this.list){this._b[k] = parseFloat( this.currentStyle()[k] ) || 0;this._c[k] = parseFloat( this.list[k] ) - this._b[k];}if( this.dom._animate ){this.dom._animate.stop();}this.run();this.dom._animate = this;},currentStyle:function(){var element = this.dom;return element.currentStyle || document.defaultView.getComputedStyle(element, null);},run:function(){if( this._t > this._d ){if( M.typeOf(this.callback) == "function" ){this.callback();}return;}else if(this._stop){return;}else{for(var k in this.list){var r = this.tween[ this.tweenType ]( this._t , this._b[k] , this._c[k] ,this._d ) + ( ("opacity|".indexOf(k+"|")>-1)?"":"px");this.dom.style[k] = r;}this._t++;requestAnimFrame( M.bindFunction(this,this.run) ,this.preTime );}},stop:function(){this._stop = true;},tween : {easeIn: function(t,b,c,d){return c*(t/=d)*t*t*t + b;},easeOut: function(t,b,c,d){return -c * ((t=t/d-1)*t*t*t - 1) + b;},easeInOut: function(t,b,c,d){if ((t/=d/2) < 1) return c/2*t*t*t*t + b;return -c/2 * ((t-=2)*t*t*t - 2) + b;},linear: function(t,b,c,d){ return c*t/d + b; }}}M.Animate.prototype.init.prototype = M.Animate.prototype;
版权所有:www.meilele.com
0 0
- js 动画封装
- JS动画封装
- js链式动画封装
- JS动画函数的封装
- JS封装缓动动画函数
- js 匀速/缓动动画 简单封装
- js实现图片旋转动画的封装
- js缓动动画函数封装
- js缓动动画及其封装
- js-匀速/缓动动画-简单封装
- JS特效之简单动画封装
- js的动画效果(封装运动框架)
- 原生js封装好的动画函数+jQuery函数animate
- 核心动画(UIView封装动画)
- JS封装
- js封装
- Js封装
- js封装
- 各类导航网址源码
- 批处理程序总结(后期逐步补充)
- 顺序线性列表的增删查改
- Java数组——复制数组copyof()
- boost 1.55在GCC 4.8.2 下的BUG
- js 动画封装
- scheduling.quartz.CronTriggerBean has interface org.quartz.CronTrigger as super class
- storm理解
- mutating method sent to immutable object
- java.lang.NoSuchMethodError: android.widget.Button.setBackground
- UML_用例图
- 程序员技术网站
- 对话黑客:四款最佳的反监控移动APP
- IE9出现异常SCRIPT5011:不能执行已释放Script的代码