frame-animation
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.animation=e():t.animation=e()}(this,function(){return function(t){function e(i){if(n[i])return n[i].exports;var s=n[i]={exports:{},id:i,loaded:!1};return t[i].call(s.exports,s,s.exports,e),s.loaded=!0,s.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function i(t){t&&t()}function s(){this.taskQueue=[],this.timeline=new r,this.state=a,this.index=0}var r=n(1),o=n(2),a=0,u=1,h=2,c=0,p=1;s.prototype.loadImage=function(t){var e=function(e){o(t.slice(),e)},n=c;return this._add(e,n)},s.prototype.changePosition=function(t,e,n){var s,r,o=e.length;if(o){var a=this;s=function(i,s){n&&(t.style.backgroundImage="url("+n+")");var r=Math.min(s/a.interval|0,o-1),u=e[r].split(" ");t.style.backgroundPosition=u[0]+"px "+u[1]+"px",r===o-1&&i()},r=p}else s=i,r=c;return this._add(s,r)},s.prototype.changeSrc=function(t,e){var n,s,r=e.length;if(r){var o=this;n=function(n,i){var s=Math.min(i/o.interval|0,r-1);t.src=e[s],s===r-1&&n()},s=p}else n=i,s=c;return this._add(n,s)},s.prototype.enterFrame=function(t){return this._add(t,p)},s.prototype.then=function(t){var e=function(e){t(),e()},n=c;return this._add(e,n)},s.prototype.start=function(t){return this.state===u?this:this.taskQueue.length?(this.state=u,this.interval=t,this._runTask(),this):this},s.prototype.repeat=function(t){var e=this,n=function(){if("undefined"==typeof t)return e.index--,void e._runTask();if(t)t--,e.index--,e._runTask();else{var n=e.taskQueue[e.index];e._next(n)}},i=c;return this._add(n,i)},s.prototype.repeatForever=function(){return this.repeat()},s.prototype.wait=function(t){return this.taskQueue&&this.taskQueue.length>0&&(this.taskQueue[this.taskQueue.length-1].wait=t),this},s.prototype.pause=function(){return this.state===u?(this.state=h,this.timeline.stop(),this):this},s.prototype.restart=function(){return this.state===h?(this.state=u,this.timeline.restart(),this):this},s.prototype.dispose=function(){return this.state!==a?(this.state=a,this.taskQueue=null,this.timeline.stop(),this.timeline=null,this):this},s.prototype._add=function(t,e){return this.taskQueue.push({taskFn:t,type:e}),this},s.prototype._runTask=function(){if(this.taskQueue&&this.state===u){if(this.index===this.taskQueue.length)return void this.dispose();var t=this.taskQueue[this.index];t.type===c?this._syncTask(t):this._asyncTask(t)}},s.prototype._syncTask=function(t){var e=this,n=function(){e._next(t)},i=t.taskFn;i(n)},s.prototype._asyncTask=function(t){var e=this,n=function(n){var i=t.taskFn,s=function(){e.timeline.stop(),e._next(t)};i(s,n)};this.timeline.onenterframe=n,this.timeline.start(this.interval)},s.prototype._next=function(t){var e=this;this.index++,t.wait?setTimeout(function(){e._runTask()},t.wait):this._runTask()},t.exports=function(){return new s}},function(t,e){"use strict";function n(){this.animationHandler=0,this.state=r}function i(t,e){function n(){var s=+new Date;t.animationHandler=u(n),s-i>=t.interval&&(t.onenterframe(s-e),i=s)}var i=+new Date;t.startTime=e,n.interval=t.interval,n()}var s=1e3/60,r=0,o=1,a=2;n.prototype.onenterframe=function(t){},n.prototype.start=function(t){this.state!==o&&(this.state=o,this.interval=t||s,i(this,+new Date))},n.prototype.restart=function(){this.state!==o&&this.dur&&this.interval&&(this.state=o,i(this,+new Date-this.dur))},n.prototype.stop=function(){this.state===o&&(this.state=a,this.startTime&&(this.dur=+new Date-this.startTime),h(this.animationHandler))};var u=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||function(t){return window.setTimeout(t,t.interval||s)}}(),h=function(){return window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||function(t){window.clearTimeout(t)}}();t.exports=n},function(t,e){"use strict";function n(){return++s}function i(t,e,i){function s(t){function n(){i.onload=i.onerror=null;try{delete window[t.id]}catch(n){}--o||h||(clearTimeout(u),e(a))}t.status="loading";var i=t.img;i.onload=function(){a=a&&!0,t.status="loaded",n()},i.onerror=function(){a=!1,t.status="error",n()},i.src=t.src}function r(){h=!0,e(!1)}var o=0,a=!0,u=0,h=!1;for(var c in t)if(t.hasOwnProperty(c)){var p=t[c];"string"==typeof p&&(p=t[c]={src:p}),p&&p.src&&(o++,p.id="__img_"+c+n(),p.img=window[p.id]=new Image,s(p))}o?i&&(u=setTimeout(r,i)):e(a)}var s=0;t.exports=i}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.animation=e():t.animation=e()}(this,function(){return function(t){function e(i){if(n[i])return n[i].exports;var s=n[i]={exports:{},id:i,loaded:!1};return t[i].call(s.exports,s,s.exports,e),s.loaded=!0,s.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function i(t){t&&t()}function s(){this.taskQueue=[],this.timeline=new r,this.state=a,this.index=0}var r=n(1),o=n(2),a=0,u=1,h=2,c=0,p=1;s.prototype.loadImage=function(t){var e=function(e){o(t.slice(),e)},n=c;return this._add(e,n)},s.prototype.changePosition=function(t,e,n){var s,r,o=e.length;if(o){var a=this;s=function(i,s){n&&(t.style.backgroundImage="url("+n+")");var r=Math.min(s/a.interval|0,o-1),u=e[r].split(" ");t.style.backgroundPosition=u[0]+"px "+u[1]+"px",r===o-1&&i()},r=p}else s=i,r=c;return this._add(s,r)},s.prototype.changeSrc=function(t,e){var n,s,r=e.length;if(r){var o=this;n=function(n,i){var s=Math.min(i/o.interval|0,r-1);t.src=e[s],s===r-1&&n()},s=p}else n=i,s=c;return this._add(n,s)},s.prototype.enterFrame=function(t){return this._add(t,p)},s.prototype.then=function(t){var e=function(e){t(this),e()},n=c;return this._add(e,n)},s.prototype.start=function(t){return this.state===u?this:this.taskQueue.length?(this.state=u,this.interval=t,this._runTask(),this):this},s.prototype.repeat=function(t){var e=this,n=function(){if("undefined"==typeof t)return e.index--,void e._runTask();if(t)t--,e.index--,e._runTask();else{var n=e.taskQueue[e.index];e._next(n)}},i=c;return this._add(n,i)},s.prototype.repeatForever=function(){return this.repeat()},s.prototype.wait=function(t){return this.taskQueue&&this.taskQueue.length>0&&(this.taskQueue[this.taskQueue.length-1].wait=t),this},s.prototype.pause=function(){return this.state===u?(this.state=h,this.timeline.stop(),this):this},s.prototype.restart=function(){return this.state===h?(this.state=u,this.timeline.restart(),this):this},s.prototype.dispose=function(){return this.state!==a?(this.state=a,this.taskQueue=null,this.timeline.stop(),this.timeline=null,this):this},s.prototype._add=function(t,e){return this.taskQueue.push({taskFn:t,type:e}),this},s.prototype._runTask=function(){if(this.taskQueue&&this.state===u){if(this.index===this.taskQueue.length)return void this.dispose();var t=this.taskQueue[this.index];t.type===c?this._syncTask(t):this._asyncTask(t)}},s.prototype._syncTask=function(t){var e=this,n=function(){e._next(t)},i=t.taskFn;i(n)},s.prototype._asyncTask=function(t){var e=this,n=function(n){var i=t.taskFn,s=function(){e.timeline.stop(),e._next(t)};i(s,n)};this.timeline.onenterframe=n,this.timeline.start(this.interval)},s.prototype._next=function(t){var e=this;this.index++,t.wait?setTimeout(function(){e._runTask()},t.wait):this._runTask()},t.exports=function(){return new s}},function(t,e){"use strict";function n(){this.animationHandler=0,this.state=r}function i(t,e){function n(){var s=+new Date;t.animationHandler=u(n),s-i>=t.interval&&(t.onenterframe(s-e),i=s)}var i=+new Date;t.startTime=e,n.interval=t.interval,n()}var s=1e3/60,r=0,o=1,a=2;n.prototype.onenterframe=function(t){},n.prototype.start=function(t){this.state!==o&&(this.state=o,this.interval=t||s,i(this,+new Date))},n.prototype.restart=function(){this.state!==o&&this.dur&&this.interval&&(this.state=o,i(this,+new Date-this.dur))},n.prototype.stop=function(){this.state===o&&(this.state=a,this.startTime&&(this.dur=+new Date-this.startTime),h(this.animationHandler))};var u=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||function(t){return window.setTimeout(t,t.interval||s)}}(),h=function(){return window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||function(t){window.clearTimeout(t)}}();t.exports=n},function(t,e){"use strict";function n(){return++s}function i(t,e,i){function s(t){function n(){i.onload=i.onerror=null;try{delete window[t.id]}catch(n){}--o||h||(clearTimeout(u),e(a))}t.status="loading";var i=t.img;i.onload=function(){a=a&&!0,t.status="loaded",n()},i.onerror=function(){a=!1,t.status="error",n()},i.src=t.src}function r(){h=!0,e(!1)}var o=0,a=!0,u=0,h=!1;for(var c in t)if(t.hasOwnProperty(c)){var p=t[c];"string"==typeof p&&(p=t[c]={src:p}),p&&p.src&&(o++,p.id="__img_"+c+n(),p.img=window[p.id]=new Image,s(p))}o?i&&(u=setTimeout(r,i)):e(a)}var s=0;t.exports=i}])}); |
{ | ||
"name": "frame-animation", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "a common animation lib", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -16,3 +16,3 @@ animation | ||
npm 安装 | ||
### npm 安装 | ||
@@ -23,6 +23,27 @@ ``` | ||
使用方法 | ||
### 示例 | ||
#### HTML | ||
```html | ||
<div id="demo"></div> | ||
``` | ||
#### CSS | ||
```css | ||
#demo { | ||
width: 100px; | ||
height: 100px; | ||
background: url('foo.png'); | ||
} | ||
``` | ||
#### JavaScript | ||
``` javascript | ||
var animation = require("animation"); | ||
var animation = require("frame-animation"); | ||
var ele = document.getElementById('demo'); | ||
var frameMap = ['0 0', '0 -100', '0 -200']; | ||
@@ -29,0 +50,0 @@ var demoAnimation = animation().changePosition(ele, positions).repeat(); |
@@ -134,3 +134,3 @@ 'use strict'; | ||
var taskFn = function (next) { | ||
callback(); | ||
callback(this); | ||
next(); | ||
@@ -137,0 +137,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
182016
90