`
xmy20051643
  • 浏览: 39680 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

extjs 5 sliderCard布局

 
阅读更多

参考很久前一个布局做的,SLIDERCARD布局,左右上下斜划动切换当前的CONTAINER中的内容。

 

/**
 * extjs slide card layout
 *
 *
 * @author <a href='mailto:xiaomingyang@aksl.com.cn'>xiaomingyang</a> 2016-01-29,16:16
 * @version v0.1
 * @since 5.0
 */
Ext.define('Ext.layout.container.SlideCard', {

    extend: 'Ext.layout.container.Fit',
    alternateClassName: 'Ext.layout.SlideCardLayout',
    alias: 'layout.slidecard',

    type: 'slidecard',
    hideInactive: true,

    deferredRender: false,
    getRenderTree: function() {
        var me = this,
            activeItem = me.getActiveItem();
        if (activeItem) {

            if (activeItem.hasListeners.beforeactivate && activeItem.fireEvent('beforeactivate', activeItem) === false) {



                activeItem = me.activeItem = me.owner.activeItem = null;
            }

            else if (activeItem.hasListeners.activate) {
                activeItem.on({
                    boxready: function() {
                        activeItem.fireEvent('activate', activeItem);
                    },
                    single: true
                });
            }
            if (me.deferredRender) {
                if (activeItem) {
                    return me.getItemsRenderTree([
                        activeItem
                    ]);
                }
            } else {
                return me.callParent(arguments);
            }
        }
    },
    renderChildren: function() {
        var me = this,
            active = me.getActiveItem();
        if (!me.deferredRender) {
            me.callParent();
        } else if (active) {

            me.renderItems([
                active
            ], me.getRenderTarget());
        }
    },
    isValidParent: function(item, target, position) {


        var itemEl = item.el ? item.el.dom : Ext.getDom(item);
        return (itemEl && itemEl.parentNode === (target.dom || target)) || false;
    },

    getActiveItem: function() {
        var me = this,




            item = me.activeItem === undefined ? (me.owner && me.owner.activeItem) : me.activeItem,
            result = me.parseActiveItem(item);

        if (result && me.owner.items.indexOf(result) !== -1) {
            me.activeItem = result;
        }



        return result == null ? null : (me.activeItem || me.owner.activeItem);
    },

    parseActiveItem: function(item) {
        var activeItem;
        if (item && item.isComponent) {
            activeItem = item;
        } else if (typeof item === 'number' || item === undefined) {
            activeItem = this.getLayoutItems()[item || 0];
        } else if (item === null) {
            activeItem = null;
        } else {
            activeItem = this.owner.getComponent(item);
        }
        return activeItem;
    },


    configureItem: function(item) {
        item.setHiddenState(item !== this.getActiveItem());
        this.callParent(arguments);
    },
    onRemove: function(component) {
        this.callParent([
            component
        ]);
        if (component === this.activeItem) {


            this.activeItem = undefined;
        }
    },

    getAnimation: function(newCard, owner) {
        var newAnim = (newCard || {}).cardSwitchAnimation;
        if (newAnim === false) {
            return false;
        }
        return newAnim || owner.cardSwitchAnimation;
    },

    getNext: function() {
        var wrap = arguments[0],
            items = this.getLayoutItems(),
            index = Ext.Array.indexOf(items, this.activeItem);
        return items[index + 1] || (wrap ? items[0] : false);
    },

    next: function() {
        var anim = arguments[0],
            wrap = arguments[1];
        return this.setActiveItem(this.getNext(wrap), anim);
    },

    getPrev: function() {
        var wrap = arguments[0],
            items = this.getLayoutItems(),
            index = Ext.Array.indexOf(items, this.activeItem);
        return items[index - 1] || (wrap ? items[items.length - 1] : false);
    },

    prev: function() {
        var anim = arguments[0],
            wrap = arguments[1];
        return this.setActiveItem(this.getPrev(wrap), anim);
    },

    setActiveItem: function(newCard) {
        var me = this,
            owner = me.owner,
            oldCard = me.activeItem,
            rendered = owner.rendered,
            newIndex, focusNewCard;
        newCard = me.parseActiveItem(newCard);
        newIndex = owner.items.indexOf(newCard);


        if (newIndex === -1) {
            newIndex = owner.items.items.length;
            Ext.suspendLayouts();
            newCard = owner.add(newCard);
            Ext.resumeLayouts();
        }

        if (newCard && oldCard !== newCard) {

            if (newCard.fireEvent('beforeactivate', newCard, oldCard) === false) {
                return false;
            }
            if (oldCard && oldCard.fireEvent('beforedeactivate', oldCard, newCard) === false) {
                return false;
            }
            if (rendered) {
                Ext.suspendLayouts();

                if (!newCard.rendered) {
                    me.renderItem(newCard, me.getRenderTarget(), owner.items.length);
                }
                if (oldCard) {
                    if (me.hideInactive) {
                        focusNewCard = oldCard.el.contains(Ext.Element.getActiveElement());
                        oldCard.hide();
                        if (oldCard.hidden) {
                            oldCard.hiddenByLayout = true;
                            oldCard.fireEvent('deactivate', oldCard, newCard);
                        } else
                        {
                            return false;
                        }
                    }
                }

                if (newCard.hidden) {
                    newCard.show();
                }


                if (newCard.hidden) {
                    me.activeItem = newCard = null;
                } else {
                    me.activeItem = newCard;




                    if (focusNewCard) {
                        if (!newCard.defaultFocus) {
                            newCard.defaultFocus = ':focusable';
                        }
                        newCard.focus();
                    }
                }
                Ext.resumeLayouts(true);
            } else {
                me.activeItem = newCard;
            }
            newCard.fireEvent('activate', newCard, oldCard);
            return me.activeItem;
        }
        return false;
    },

    /**
     * tl左上角( 默认) t上居中 tr右上角
     * l左边界的中央 c居中
     * r右边界的中央 bl左下角 b下居中 br右下角
     *
     * @param item
     * @param direct
     * @param callback
     * @param scope
     * @param options
     */
    slideActive : function(item, direct, callback, scope, options) {
        var me = this, ai = this.activeItem,
            ct = this.container;
        item = me.parseActiveItem(item);
        var redrect = direct;
        if (scope === 0) {
            scope = item;
        }
        if (item && ai != item) {
            var l = this;
            var  callbackF = function() {
                var layout = item.doLayout && (l.layoutOnCardChange || !item.rendered);
                l.activeItem = item;
                delete item.deferLayout;
                item.show();
                //if (item.slidouted) {
                //    item.el.slideIn('l', {//将元素从视图滑出并伴随着渐隐
                //        easing : 'ease',
                //        duration : 800,
                //        remove : false
                //    });
                //}
                l.layout();
                ct.doLayout();
                if (layout) {
                    item.doLayout();
                }
                item.fireEvent('activate', item);
                if (callback) {
                    callback.apply(scope,options);
                }
            };
            if (ai) {
                ai.el.slideOut(direct, {//将元素从视图滑出并伴随着渐隐
                    easing : 'ease',
                    duration : 500,
                    remove : false,
                    callback : function(){
                        ai.slidouted = true;
                        ai.hide();
                        callbackF();
                    }
                });
            }else{
                callbackF();
            }
        }
    }
});

 ===================================================

Ext.apply(this, {
            items: [{
                border : false,
                frame : false,
                layout : 'fit',
                bodyStyle:'padding:2px',
                items : [{
                    id : 'role-card-containner',
                    border : false,
                    activeItem: 0,
                    layout : 'slidecard',
                    items : [this._roleGrid, this._roleAddForm, this._roleViewForm]
                }]
            }]
        });

 ==========================================================

切换卡片

 /**
     * 添加角色
     *
     * @private
     */
    _addRoleItem : function() {
        var currentActiveItem = Ext.getCmp('role-card-containner').getLayout().getActiveItem();
        var activeIndex = currentActiveItem.id.substr(this._comp_id_prefix.length);
        var nextIndex = eval(activeIndex) + 1;
        Ext.getCmp('role-card-containner').getLayout().slideActive(nextIndex, 'l');
    },

 

分享到:
评论

相关推荐

    ExtJs4 layout 布局

    ExtJs4 layout 布局 这是鄙人之前自学Ext时收集的文档,详细讲诉了各种布局,并附源码与界面展示,希望能给你带来帮助

    ExtJS3.2列布局

    列布局(Column Layout)是ExtJS的一种布局策略,它允许你在同一行内创建多个并排显示的区域,每个区域可以包含不同的组件,如文本框、选择框、按钮等。这种布局方式非常适合用来构建表格化的表单,使得数据输入和...

    ExtJs4.2首页布局示例

    左边菜单,右边是内容,北边是log图片 简单首页布局示例

    Extjs4 layout 布局

    用extjs4搭的一个简单布局框架

    extjs_页面布局.doc

    5. **AnchorLayout**:锚点布局,允许组件根据容器大小动态调整大小。通过设置组件的锚点属性,可以使其在容器的边缘对齐或保持相对比例。 6. **AbsoluteLayout**:绝对位置布局,每个子组件的位置通过坐标(x, y)来...

    ExtJS4ExtJS5MD5 加密

    适用于ExtJS4、ExtJS5 MD5加密算法!

    ExtJs常用布局--layout详解实例代码

    ExtJs常用布局--layout详解实例代码: ExtJs常见的布局方式有:border、form、absolute、column、accordion、table、fit、card、anchor 另外,不常见的布局有:tab、vbox、hbox 具体使用方法可见该文件的案例代码。 ...

    Extjs面板和布局

    ### Extjs面板和布局知识点详解 #### 一、Extjs中的面板(Panel) 在Extjs中,**面板(Panel)**扮演着极其重要的角色,它不仅作为其他组件的容器,而且还是实现页面布局的关键手段之一。面板类似于Delphi、Visual...

    EXTJS面板及布局类(DOC)

    ExtJS不但在Web开发中成功引入了丰富的组件,也引入了桌面程序中经常用到的面板及布局概念。这些概念的引入在很大程度上改变了传统的Web开发方式,在第3章和第4章中主要学习了ExtJS支持的各种组件,本章将进一步学习...

    ExtJS布局之border实例

    资源名称:ExtJS布局之border实例内容简介:border布局是常见的布局样式,本文档中一个实际项目的示例,比较简单,仅供初学者参考。感兴趣的朋友可以过来看看。自动生成行号,支持checkbox全选,动态选择显示哪些列...

    跟我一起学extjs5前20节的代码

    EXTJS5 是一款基于 JavaScript 的富客户端框架,用于构建数据驱动的桌面级 Web 应用。这个压缩包包含了“跟我一起学EXTJS5前20节的代码”学习资源,帮助初学者逐步掌握EXTJS5的基本概念和使用方法。下面我们将深入...

    ExtJs布局教程Ext详细布局

    ExtJS布局是构建用户界面的关键部分,特别是在使用ExtJS库时。本文主要讲解ExtJS的Column布局,一种非常灵活的布局方式,可以帮助开发者创建复杂的、响应式的用户界面。 Column布局在ExtJS中用于将容器(如Panel)...

    ExtjS--accordion布局

    在本篇博客中,我们将聚焦于"accordion布局"这一特性,它是ExtJS布局系统中的一种特殊形式。 Accordion布局,又称为折叠面板布局,允许在一个容器内放置多个面板,这些面板会像手风琴一样展开和折叠。这种布局模式...

    ExtJS 七种布局.pptx

    Extjs 的各种布局详解,和案例使用,包括各种属性的介绍。免费送给需要的朋友。简单并且实用,有需要的朋友自己下载。

    Extjs中布局的组合使用中文WORD版

    资源名称:Extjs中布局的组合使用 中文WORD版内容简介:本文档主要讲述的是Extjs中布局的组合使用;Extjs4.1中布局很经典,也很好用,关键是如何组合布局,组合布局,不仅要达到我们想要的界面效果,还要注意因为...

    Extjs4.1布局与树

    纯Extjs代码,对初学Ext有点点帮助

    Extjs布局实例

    Extjs布局实例

    extjs页面布局生成器

    很好的ext页面布局自动生成功能,快速布局,减少你页面开发时间!用法:解压-&gt;添加文件夹到一个web工程当中-&gt;进入index.html进入页面编辑就可以自由设计你的布局了,代码在查看/修改中可以看到,只需复制粘贴到自己...

    Extjs5官方可运行实例Ticket App

    ExtJS 5的布局系统允许开发者灵活地组织组件,适应不同的屏幕尺寸和设备。Ticket App可能使用网格布局来展示票列表,使用表单布局来创建和编辑票信息。 9. **主题与皮肤(Themes & Skins)** ExtJS 5提供了多种...

    ExtJS5 整合Spring4之二

    标题 "ExtJS5 整合Spring4之二" 暗示了这是一个关于将流行的JavaScript框架ExtJS5与Java后端框架Spring4集成的主题。在Web应用开发中,这种集成允许开发者利用ExtJS5的富客户端功能和Spring4的强大后端服务。下面将...

Global site tag (gtag.js) - Google Analytics