extjs - 如何使用卡片布局获得动画

标签 extjs extjs4.2

我正在为我的向导类型应用程序使用卡片布局。单击下一个和上一个按钮时如何实现动画效果。

var navigate = function(panel, direction){
     var layout = panel.getLayout();
    layout[direction]();
    Ext.getCmp('move-prev').setDisabled(!layout.getPrev());
    Ext.getCmp('move-next').setDisabled(!layout.getNext());
};
Ext.create('Ext.panel.Panel', {
    title: 'Example Wizard',
    width: 300,
    height: 200,
    layout: {type: 'card'   ,
            animation: {
                type: 'slide',
            }},
    bodyStyle: 'padding:15px',
    defaults: {
        border: false
    },
    bbar: [
        {
            id: 'move-prev',
            text: 'Back',
            handler: function(btn) {
                navigate(btn.up("panel"), "prev");
            },
            disabled: true
        },
        '->',
        {
            id: 'move-next',
            text: 'Next',
            handler: function(btn) {
                navigate(btn.up("panel"), "next");
            }
        }
    ],
    items: [{
        id: 'card-0',
        html: '<h1>Welcome to the Wizard!</h1><p>Step 1 of 3</p>'
    },{
        id: 'card-1',
        html: '<p>Step 2 of 3</p>'
    },{
        id: 'card-2',
        html: '<h1>Congratulations!</h1><p>Step 3 of 3 - Complete</p>'
    }],
    renderTo: Ext.getBody()
});

最佳答案

我能够通过覆盖 setActiveItem 来实现动画淡出卡片布局的方法。您可以在此处查看示例的操作:http://jsfiddle.net/q7Ytj/4/ .

只需在应用程序初始化步骤中执行此操作:

Ext.override(Ext.layout.container.Card, {
    setActiveItem: function (newCard) {
        var me = this,
            owner = me.owner,
            oldCard = me.activeItem,
            rendered = owner.rendered,
            newIndex;

        newCard = me.parseActiveItem(newCard);
        newIndex = owner.items.indexOf(newCard);

        // If the card is not a child of the owner, then add it.
        // Without doing a layout!
        if (newIndex === -1) {
            newIndex = owner.items.items.length;
            Ext.suspendLayouts();
            newCard = owner.add(newCard);
            Ext.resumeLayouts();
        }

        // Is this a valid, different card?
        if (newCard && oldCard !== newCard) {
            // Fire the beforeactivate and beforedeactivate events on the cards
            if (newCard.fireEvent('beforeactivate', newCard, oldCard) === false) {
                return false;
            }
            if (oldCard && oldCard.fireEvent('beforedeactivate', oldCard, newCard) === false) {
                return false;
            }

            if (rendered) {
                Ext.suspendLayouts();

                // If the card has not been rendered yet, now is the time to do so.
                if (!newCard.rendered) {
                    me.renderItem(newCard, me.getRenderTarget(), owner.items.length);
                }

                var handleNewCard = function () {
                    // Make sure the new card is shown
                    if (newCard.hidden) {
                        newCard.show();
                    }

                    if (!newCard.tab) {
                        var newCardEl = newCard.getEl();
                        newCardEl.dom.style.opacity = 1;
                        if (newCardEl.isStyle('display', 'none')) {
                            newCardEl.setDisplayed('');
                        } else {
                            newCardEl.show();
                        }
                    }

                    // Layout needs activeItem to be correct, so set it if the show has not been vetoed
                    if (!newCard.hidden) {
                        me.activeItem = newCard;
                    }
                    Ext.resumeLayouts(true);
                };

                var handleOldCard = function () {
                    if (me.hideInactive) {
                        oldCard.hide();
                        oldCard.hiddenByLayout = true;
                    }
                    oldCard.fireEvent('deactivate', oldCard, newCard);
                };

                if (oldCard && !newCard.tab) {
                    var oldCardEl = oldCard.getEl();
                    oldCardEl.fadeOut({
                        callback: function () {
                            handleOldCard();
                            handleNewCard();
                        }
                    });

                } else if (oldCard) {
                    handleOldCard();
                    handleNewCard();
                } else {
                    handleNewCard();
                }

            } else {
                me.activeItem = newCard;
            }

            newCard.fireEvent('activate', newCard, oldCard);

            return me.activeItem;
        }
        return false;
    }
});

关于extjs - 如何使用卡片布局获得动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18200489/

相关文章:

javascript - 如何将子项添加到 TreePanel 中的节点?

javascript - Ext JS SuperBoxSelect 组件

javascript - Ext js 获取选中的组记录

javascript - 如何从 html 文件创建 sencha touch xtemplate

javascript - 具有自动建议功能的 Extjs 级联组合框

javascript - Extjs 5将 Accordion 按钮移动到标题左侧

javascript - 在数组中添加元素时未捕获非法访问

javascript - 如何使用 ExtJs rowexpander 展开或折叠所有行?

javascript - ExtJS 4.2.1 : Using "split" in border layout in panel, 调整大小问题

javascript - ExtJs5 -Ext.View.View 隐藏在 Ext 网格下方,仅在刷新后重新出现