這裏是你可以用它來完成這個
function animatron (target, prop, duration, to, from, easing) {
// return if no target or prop
if (target == null || prop == null) { return; }
// defaults
if (duration == null) { duration = 250; }
if (to == null) { to = 0; }
if (from == null) { from = target.getHeight(); }
if (easing == null) { easing = 'ease-out'; }
// to property
var t = {};
t[prop] = to;
// from property
var f = {};
f[prop] = from;
// Animation Options
var opts = {
duration: duration,
easing: easing,
element: target.element,
from: f,
preserveEndState: true,
to: t
};
// Animation Object
var anime = new Ext.fx.Animation(opts);
// On animationend Event
anime.on('animationend', function (animation, element, isInterrupted) {
// Hide the target if the to is 0
if (to == 0 && (prop == 'height' || prop == 'width')) {
if (!isInterrupted) { target.hide(); }
}
// Update property if width or height
if (prop == 'height') { target.setHeight(to); }
if (prop == 'width') { target.setWidth(to); }
// Dispatch 'animated' event to target
target.fireEvent('animated', animation, element, to, from, isInterrupted);
});
// Show the target if it's hidden and to isn't 0
if (target.getHidden() == true && to != 0) { target.show(); }
// Run the animation
Ext.Animator.run(anime);
}
您可以監聽目標元素上的「動畫」事件
animatron(dataview, 'height', 500, 0);
dataview.addListener('animated', function (animation, element, to, from, isInterrupted) {
console.log('animation ended');
console.log('interrupted: '+ isInterrupted);
});
謝謝,一個可行的清潔效用函數。只是我,還是沒有任何動畫師的文檔? – kmc 2012-03-26 22:16:38
目前,沒有。原因是我們(Sencha)想在2.1中更詳細地看它,或許改變它的工作方式。我們不想用2.1更新打破人們的應用程序,所以我們採取了保留現有的動畫系統(Ext.Anim),這是一種錯誤(正如您所經歷的),直到我們修復了Ext.Animator。現在,您最好的選擇是查看源代碼並查看可用的屬性。你最好的開始是看着'src/fx/animation/Abstract.js'。 – rdougan 2012-03-26 22:34:25
再次感謝。考慮動畫師爲Sencha 2.1投票!將使我的應用更光滑。 – kmc 2012-03-27 12:01:09