Disable dragging in Carousel

╄→гoц情女王★ 提交于 2019-12-22 06:48:04

问题


Is it possible to disable usage of dragging to swap between Carousel panels? I want use just indicator.


回答1:


Try override afterRender method in Carousel;(I removed drag events on childs method)

   afterRender : function() {
        Ext.Carousel.superclass.afterRender.call(this);
        this.mon(this.body, {
        direction : this.direction,
        scope : this
        });
        this.el.addCls(this.baseCls + "-" + this.direction)
    }

Whole code;

 this.car =  new Ext.Carousel({
                ui       : 'light',
                items: [
                {
                        html: '<p>Carousels can be vertical and given a ui of "light" or "dark".</p>',
                        cls : 'card card1'
                    },
                    {
                        html: 'Card #2',
                        cls : 'card card2'
                    },
                    {
                        html: 'Card #3',
                        cls : 'card card3'
                    }],
                        afterRender : function() {
                            Ext.Carousel.superclass.afterRender.call(this);
                            this.mon(this.body, {
                                direction : this.direction,
                                scope : this
                            });
                            this.el.addCls(this.baseCls + "-" + this.direction)
                        }
        });



回答2:


Just throwing this out there for the Sencha Touch 2.0 people. The above solution doesn't work for Sencha Touch 2.0, but there is a pretty easy work around.

Ext.define('Ext.LockableCarousel', {
    extend: 'Ext.Carousel',
    id: 'WelcomeCarousel',
    initialize: function () {
       this.onDragOrig = this.onDrag;
       this.onDrag = function (e) { if(!this.locked){this.onDragOrig(e);} }
    },
    locked: false,
    lock: function () { this.locked = true; },
    unlock: function () { this.locked = false; }
});

This will function exactly like a carousel, except now you can call .lock and .unlock on it. So you could do something like:

Ext.Viewport.add(Ext.create('Ext.LockableCarousel', { 
     id: 'LockableCarousel',
     fullscreen: true,
     hidden: false,
     items: [
        {
           html : 'Item 1',
           style: 'background-color: #5E99CC'
        },
        {
           html : '<a href="#" onclick="Ext.getCmp(\'LockableCarousel\').lock();">Lock</a><br /><a href="#" onclick="Ext.getCmp(\'LockableCarousel\').unlock();">Unlock</a>',
           style: 'background-color: #759E60'
        }
     ]
}));


来源:https://stackoverflow.com/questions/8283196/disable-dragging-in-carousel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!