2011-11-27 66 views

回答

1

嘗試倍率AfterRender階段在旋轉木馬方法;(I除去上兒童的方法拖拽事件)

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

謝謝,它的工作原理。但我不確定它是如何做的:)你能解釋一下嗎? – Egor4eg

+1

當然。想法很簡單。我們必須禁用拖動,在這種情況下,可以通過移除拖動監聽器來進行拖動。在sencha-touch.js中的afterRender方法中添加拖動偵聽器。我們重寫afterRender方法,因此sencha-touch的afterRender方法不會運行,我們的新方法將運行,並且我們的方法不會添加拖拽偵聽器。我希望這個描述很清楚。 :) –

+0

謝謝,我明白了。 – Egor4eg

10

只爲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' 
     } 
    ] 
})); 
+0

感謝您的代碼示例。它甚至禁用了指示器,所以它確實是我暫時鎖定旋轉木馬所需的一切。 –

+0

非常簡單。我將'locked'var移動到配置對象中,以便在添加自定義輪播時設置默認鎖定狀態。這改變訪問被鎖定的var以:this.getLocked(); – daxiang28

+0

非常好的解決方案,效果很好。謝謝! – Phil