2012-09-04 50 views
3

我使用的Ember.js與把手,我需要使我的頁面內的div摺疊/展開時單擊。我知道如何在jQuery中做到這一點,但我不能使用任何jQuery。有誰知道如何做到這一點?此外,我不想只切換隱藏屬性,我需要完整的滑動上下功能以進行摺疊。如果有人有任何想法,我會很感激。Ember可摺疊容器

謝謝

+0

我不熟悉Ember.js,但你是否想要實現這樣的目標? http://codepen.io/thebabydino/pen/yidab – Ana

+0

是的。這是我試圖建模http://www.snyderplace.com/demos/collapsible.html(只是更好的造型)。我只需要找到一種方法來處理它與燼。我假設我需要使用一個燼視圖來做到這一點。此外,我需要將動態視圖(可能是出口......我認爲)作爲可摺疊容器的內容。 – Hoopdady

回答

2

點擊您的視圖將導致觸發點擊事件。你可以在你想要一個點擊事件處理中在你看來任何方式編寫動畫:

CollapsableView = Ember.View.extend({ 
    click : function(event) { 
     this.$().toggle('fast'); 
    } 
}) 
0

在灰燼這樣做的正確方法是通過真棒Liquid Fire插件。

綱:

  1. 安裝液體滅火到項目中。
  2. 定義這樣的過渡:

    this.transition(
        this.hasClass('transition-spoiler'), 
        this.toValue(true), 
        this.use('toDown'), 
        this.reverse('toUp') 
    ); 
    
  3. 在控制器/組件,創建一個屬性spoilerIsVisibletoggleSpoiler屬性:

    spoilerIsVisible: false, 
    
    actions: { 
        toggleSpoiler: function() { 
        this.toggleProperty('spoilerIsVisible'); 
        } 
    } 
    
  4. 在你的頁面/組件模板,創建按鈕和像這樣的擾流板包裝:

    <button {{action 'toggleSpoiler'}}> 
        {{if spoilerIsVisible 'Show spoiler' 'Hide spoiler'}} 
    </button> 
    
    {{#liquid-if spoilerIsVisible class="transition-spoiler"}} 
        <p>Dumbledore dies</p> 
    {{/liquid-if}} 
    

請注意,您可以將步驟3-4包裝成x-spoiler組件或其他東西。