【发布时间】:2011-11-27 02:28:23
【问题描述】:
是否可以禁用拖动以在轮播面板之间切换? 我只想使用指标。
【问题讨论】:
标签: sencha-touch
是否可以禁用拖动以在轮播面板之间切换? 我只想使用指标。
【问题讨论】:
标签: sencha-touch
只是为 Sencha Touch 2.0 的人们扔了这个。上述解决方案不适用于 Sencha Touch 2.0,但有一个非常简单的解决方法。
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; }
});
这将完全像一个轮播,除了现在你可以调用 .lock 和 .unlock 。所以你可以这样做:
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'
}
]
}));
【讨论】:
尝试在 Carousel 中覆盖 afterRender 方法;(我删除了 childs 方法上的拖动事件)
afterRender : function() {
Ext.Carousel.superclass.afterRender.call(this);
this.mon(this.body, {
direction : this.direction,
scope : this
});
this.el.addCls(this.baseCls + "-" + this.direction)
}
完整的代码;
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)
}
});
【讨论】: