Egor4eg
Egor4eg

Reputation: 2708

Disable dragging in Carousel

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

Upvotes: 5

Views: 4659

Answers (2)

jtymann
jtymann

Reputation: 763

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

Upvotes: 11

Yusuf K.
Yusuf K.

Reputation: 4260

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

Upvotes: 1

Related Questions