DIV CSS 佈局教程網

Ionic 上拉選單 ActionSheet 實作範例
編輯:關於JavaScript     

Ionic 的 ActionSheet 是一種從底部彈出的選單,常用於提供分享、刪除、移動等快速操作。本文示範如何在 Angular 控制器中觸發 ActionSheet。

HTML 結構

<body ng-app="starter" ng-controller="actionsheetCtl">
  <ion-pane>
    <ion-content>
      <h2 ng-click="show()">Action Sheet</h2>
    </ion-content>
  </ion-pane>
</body>

JavaScript 控制器

在 Angular 控制器中注入 $ionicActionSheet 與 $timeout,即可顯示並自動關閉選單。

.controller("actionsheetCtl", [
  "$scope",
  "$ionicActionSheet",
  "$timeout",
  function ($scope, $ionicActionSheet, $timeout) {
    $scope.show = function () {
      var hideSheet = $ionicActionSheet.show({
        buttons: [
          { text: "<b>Share</b> This" },
          { text: "Move" }
        ],
        destructiveText: "Delete",
        titleText: "Modify your album",
        cancelText: "Cancel",
        cancel: function () {
          // 可加入取消時的處理
        },
        buttonClicked: function (index) {
          return true;
        }
      });

      $timeout(function () {
        hideSheet();
      }, 2000);
    };
  }
]);

重點說明

buttons 可定義一般選項,destructiveText 通常用來標示危險操作,例如刪除。cancelText 則是取消按鈕文字。若要讓選單在指定時間後自動關閉,可使用 $timeout 呼叫 hideSheet。

透過 ActionSheet,Ionic 應用可以快速提供清楚且易於操作的行動選單。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved