4

How to get an animation with layout

 3 years ago
source link: https://www.codesd.com/item/how-to-get-an-animation-with-layout.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to get an animation with layout

advertisements

I am using card layout for my wizard type application. How can i achieve animation effect while clicking on next and previous button.

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()
});


I was able to achieve fade out in animation by overriding setActiveItem method for the card layout. You can see it action for your example here: http://jsfiddle.net/q7Ytj/4/.

Just do this on application initialization step:

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;
    }
});


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK