Ionic-js-side-menu
提供:Dev Guides
Ionic-JavaScriptサイドメニュー
サイドメニューは、最もよく使用されるIonicコンポーネントの1つです。 サイドメニューを開くには、左または右にスワイプするか、その目的のために作成されたボタンをトリガーします。
サイドメニューを使用する
必要な最初の要素は ion-side-menus です。 この要素は、サイドメニューを使用するすべての画面にサイドメニューを接続するために使用されます。 ion-side-menu-content 要素はコンテンツが配置される場所であり、 ion-side-menu 要素は side ディレクティブを配置できる場所です。 indexl にサイドメニューを追加し、サイドメニューのコンテンツ内に ion-nav-view を配置します。 このようにして、アプリ全体でサイドメニューを使用できます。
インデックス
ここで、menu-toggle = "left" *ディレクティブを使用してボタンを作成します。 通常、このボタンはアプリのヘッダーバーに配置されますが、理解を深めるためにテンプレートファイルに追加します。
ボタンをタップするか、右にスワイプすると、サイドメニューが開きます。 サイドメニューを閉じるためだけに1つのボタンを使用したい場合は、 menu-close ディレクティブを設定することもできますが、これにはトグルボタンを使用します。
HTMLテンプレート
上記のコードは、次の画面を生成します-
サイドメニューデリゲート
コントローラコード
HTMLコード
次の表は、 $ ionicScrollDelegate メソッドを示しています。
デリゲートメソッド
Method | Parameters | Type | Details |
---|---|---|---|
toggleLeft(parameter) | isOpen | Boolean | Used for opening or closing side menu. |
toggleRight(parameter) | isOpen | Boolean | Used for opening or closing side menu. |
getOpenRatio() | / | / | Returns ratio of open part over menu width. If half of the menu is open from the left, the ration will be 0.5. If side menu is closed, it will return 0. If half of the menu is open from the right side, it will return -0.5. |
isOpen() | / | Boolean | Returns true if side menu is open, false if it is closed. |
isOpenLeft() | / | Boolean | Returns true if left side menu is open, false if it is closed. |
isOpenRight() | / | Boolean | Returns true if right side menu is open, false if it is closed. |
getScrollPosition() | / | / | Returns object with two number as properties: left *and right*. These numbers represent the distance the user has scrolled from the left and from the top respectively. |
canDragContent(parameter1) | canDrag | Boolean | Whether the content can be dragged to open side menu. |
edgeDragThreshold(parameter1) | value | Boolean | number |
If the value is true, the side menu can be opened by dragging 25px from the edges of the screen. If it is false, dragging is disabled. We can set any number that will represent pixel value from the left and right edge of the screen. | $getByHandle(parameter1) | handle | string |