【问题标题】:How do I lock a carousel in Sencha Touch如何在 Sencha Touch 中锁定轮播
【发布时间】:2013-05-04 05:59:08
【问题描述】:

我正在使用轮播并希望锁定轮播,直到单击按钮。是否有捷径可寻?谢谢!

到目前为止我的代码:

Ext.define('BabyBen.view.MainCarousel', {
    extend: 'Ext.carousel.Carousel',
    xtype: 'maincarousel',

    config: {
        fullscreen: true,

        activeItem: 1,
        indicator: false,

        scrollable: {
            direction: 'vertical',
            directionLock: true
        },

        items: [{
            xtype: 'whatscreen'
        }, {
            xtype: 'startscreen'
        }, {
            xtype: 'whenscreen'
        }]
    }
});

【问题讨论】:

  • 你的代码是什么样的?
  • @cclerville 到目前为止我有这个: Ext.define('MyApp.view.MainCarousel', { extend: 'Ext.carousel.Carousel', xtype: 'maincarousel', config: { fullscreen: true, activeItem: 1, indicator: false, scrollable: {
    方向: 'vertical', directionLock: true }, items: [{ xtype: 'whatscreen' }, { xtype: 'startscreen' }, { xtype: 'whenscreen' }] } });
  • 你能把它放在你的问题中吗?它更容易阅读。
  • @cclerville 我把它放到了你的问题中!谢谢!

标签: scroll sencha-touch sencha-touch-2 carousel


【解决方案1】:

您需要为可锁定轮播编写自定义视图:

Ext.define("myApp.view.LockableCarousel",{
    extend: 'Ext.Carousel',
    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; }
});

然后您可以使用extend 将这个自定义轮播扩展到任何地方,并且您需要通过按钮处理程序为您想要的可锁定轮播应用自定义lockunlock 函数:

Ext.define("myApp.view.CustomCarousel",{
    xtype: 'CustomCarousel',
    extend: 'myApp.view.LockableCarousel',

    config: {
        id: 'LockableCarousel',
        title: 'Example4',
        iconCls: 'cloud',
        indicator: false,        

        items: [

            {
                html : 'Item 1',
                style: 'background-color: #5E99CC'
            },

            {
                items: [
                    {
                        xtype : 'button',
                        text: 'Lock',
                        handler:function() {
                            Ext.getCmp('LockableCarousel').lock();
                        }
                    },
                    {
                        xtype : 'button',
                        text: 'Unlock',
                        handler:function() {
                            Ext.getCmp('LockableCarousel').unlock();
                        }
                    }
                ]
            }



        ]
    }
});

Working Demo

【讨论】:

  • 非常感谢!我能够锁定旋转木马。感谢您的宝贵时间。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多