如何简单地用YUI做JavaScript动画

2019-06-03 01:49:19丽君
beginSync() 告诉 animator 组合每个actions的动作,同时播放这些动画。
anim.beginSync(); 
this.minbar.move('left', this.minbar.getWidth()+this.margin, true, .35);
this.dockbar.move('right', this.dockedWidth+this.margin, true, .4, null, YAHOO.util.Easing.easeOut);
anim.endSync();
播放完成后执行这个 callback.
anim.play(this.fireDocked);

更多复杂的例子 Click here to see what it does. Sorry, this depended on an old blog layout and no longer works. I won't go step by step but notice how the code flows like a normal javascript app? You would never know that there are over 10 different asynchronous animations being sequenced. Notice the async calls too - those are calling out to my navbar and telling it to dock or undock, which also performs more animations. The Animator here waits for those animations to complete before continuing. Dont' mind my code spacing, I am big fan of spacing code into logical blocks!2
var animator = new YAHOO.ext.Animator();
var cursor = new YAHOO.ext.Actor('cursor-img', animator); 
var resize = new YAHOO.ext.Actor('resize-img', animator);
var click = new YAHOO.ext.Actor('click-img', animator); 
var splitter = new YAHOO.ext.Actor('splitter', animator);  
animator.startCapture(); 
animator.addAsyncCall(Blog.navbar.undockDelegate, 1); 
cursor.show(); 
cursor.moveTo(500,400); 
cursor.moveTo(20, getEl('navbar').getY()+10, true, .75);
click.clearOpacity();
click.show(); 
click.alignTo(cursor, 'tl', [-4, -4]);
animator.pause(.5); 
click.hide(true, .7);   
animator.addAsyncCall(Blog.navbar.dockDelegate, 1);   
cursor.alignTo('splitter', 'tr', [0, +100], true, 1);
resize.alignTo('splitter', 'tr', [-12, +100]);
animator.beginSync();
cursor.hide(); 
resize.show(); 
animator.endSync(); 
splitter.highlight('#EEEEFF', '#C3DAF9', .3);
splitter.highlight('#EEEEFF', '#C3DAF9', .3);
animator.pause(2);
resize.hide();
cursor.show();
cursor.moveTo(-100, -100, true);  
animator.stopCapture(); 
animator.play();
如果你喜欢做动画,那你一定会爱上yui,特别是现在做动画更容易了。 注意: 这些功能同样包含在 YAHOO.ext.UpdateManager里面. 这是一个使用YAHOO.util.Connect 来AJAX更新元素的简单API ,基于事件驱动使得YAHOO.util.Connect 代码更简洁。 最好的是,你亲自去看看内部的代码因为我现在实在太累了-不能再写BLOGL了!