15.04 - animation example.js

来自「JS设计模式源代码」· JavaScript 代码 · 共 36 行

JS
36
字号
// Publisher APIvar Animation = function(o) {  this.onStart = new Publisher,  this.onComplete = new Publisher,  this.onTween = new Publisher;};Animation.  method('fly', function() {    // begin animation    this.onStart.deliver();    for ( ... ) { // loop through frames      // deliver frame number      this.onTween.deliver(i);     }    // end animation    this.onComplete.deliver();  });// setup an account with the animation managervar Superman = new Animation({...config properties...});// Begin implementing subscribersvar putOnCape = function(i) { };var takeOffCape = function(i) { };putOnCape.subscribe(Superman.onStart);takeOffCape.subscribe(Superman.onComplete);// fly can be called anywhereSuperman.fly();// for instance:addEvent(element, 'click', function() {  Superman.fly();});

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?