对于简单的淡入/淡出动画,您可以简单地将WidgetAnim插件插入到您的模态实例中。默认情况下,这将以 0.2 秒的持续时间淡入和淡出您的模态。
<div id="modal"></div>
YUI().use('aui-modal', 'widget-anim', function(Y) {
var modal = new Y.Modal(
{
bodyContent: 'Modal body',
centered: true,
headerContent: '<h3>Modal header</h3>',
modal: true,
render: '#modal'
}
).render();
modal.plug(Y.Plugin.WidgetAnim);
});
此外,您可以使用animShow和animHide属性更改默认的淡入淡出动画(请注意,您需要为此使用 'anim' 模块):
modal.plug(
Y.Plugin.WidgetAnim,
{
duration: 0.5,
animHide: new Y.Anim(
{
duration: 0.5,
easing: Y.Easing.easeIn,
node: modal.get('boundingBox'),
to: { xy: [modal.get('boundingBox').getXY()[0], -500] }
}
),
animShow: new Y.Anim(
{
duration: 0.5,
easing: Y.Easing.elasticOut,
from: { xy: [modal.get('boundingBox').getXY()[0], -500] },
node: modal.get('boundingBox'),
to: { xy: modal.get('boundingBox').getXY() }
}
)
}
);