如何修改离子侧菜单?

时间:2016-05-27 09:20:32

标签: angularjs ionic-framework

我正在构建一个混合应用程序,我正在使用离子侧面模板。它工作正常。但是,我想改变我的侧面菜单,表现得像这样

http://codepen.io/xAlien95/pen/emgKpj

我的'menu.html'代码

<ion-side-menus enable-menu-with-back-views="false">
  <ion-side-menu-content>
    <ion-nav-bar class="bar-stable">
      <ion-nav-back-button>
      </ion-nav-back-button>

      <ion-nav-buttons side="left">
        <button class="button button-icon button-clear ion-navicon" menu-toggle="left">
        </button>
      </ion-nav-buttons>
    </ion-nav-bar>
    <ion-nav-view name="menuContent"></ion-nav-view>
  </ion-side-menu-content>

  <ion-side-menu side="left">
    <ion-header-bar class="bar-stable">
      <h1 class="title">Left</h1>
    </ion-header-bar>
    <ion-content>
      <ion-list>
        <ion-item menu-close ng-click="login()">
          Login
        </ion-item>
        <ion-item menu-close href="#/app/search">
          Search
        </ion-item>
        <ion-item menu-close href="#/app/browse">
          Browse
        </ion-item>
        <ion-item menu-close href="#/app/playlists">
          Playlists
        </ion-item>
      </ion-list>
    </ion-content>
  </ion-side-menu>
</ion-side-menus>

controller.js代码

angular.module('starter.controllers', [])

.controller('AppCtrl', function($scope, $ionicModal, $timeout, $window, $ionicSideMenuDelegate) {

  // With the new view caching in Ionic, Controllers are only called
  // when they are recreated or on app start, instead of every page change.
  // To listen for when this page is active (for example, to refresh data),
  // listen for the $ionicView.enter event:
  //$scope.$on('$ionicView.enter', function(e) {
  //});

  // Form data for the login modal
  $scope.loginData = {};

  // Create the login modal that we will use later
  $ionicModal.fromTemplateUrl('templates/login.html', {
    scope: $scope
  }).then(function(modal) {
    $scope.modal = modal;
  });

  // Triggered in the login modal to close it
  $scope.closeLogin = function() {
    $scope.modal.hide();
  };

  // Open the login modal
  $scope.login = function() {
    $scope.modal.show();
  };

  // Perform the login action when the user submits the login form
  $scope.doLogin = function() {
    console.log('Doing login', $scope.loginData);

    // Simulate a login delay. Remove this and replace with your login
    // code if using a login system
    $timeout(function() {
      $scope.closeLogin();
    }, 1000);
  };

  $scope.width = function () {
    return $window.innerWidth;
  };

  $scope.openMenu = function() {
    $ionicSideMenuDelegate.toggleRight(true);
  };

  $scope.isWalletShown = false;
  $scope.toggleWallet = function () {
    $scope.isWalletShown = $scope.isWalletShown === false ? true : false;
    console.log('Toggled');
  }

})

.controller('PlaylistsCtrl', function($scope) {
  $scope.playlists = [
    { title: 'Reggae', id: 1 },
    { title: 'Chill', id: 2 },
    { title: 'Dubstep', id: 3 },
    { title: 'Indie', id: 4 },
    { title: 'Rap', id: 5 },
    { title: 'Cowbell', id: 6 }
  ];
})

.controller('PlaylistCtrl', function($scope, $stateParams) {
});

app.js文件

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'starter.controllers' is found in controllers.js
angular.module('starter', ['ionic', 'starter.controllers'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);

    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }
  });
})


  .directive('fader', function ($timeout, $ionicGesture, $ionicSideMenuDelegate) {
    return {
      restrict: 'E',
      require: '^ionSideMenus',
      scope: true,
      link: function($scope, $element, $attr, sideMenuCtrl) {
        $ionicGesture.on('tap', function(e) {
          $ionicSideMenuDelegate.toggleRight(true);
        }, $element);
        $ionicGesture.on('dragleft', function(e) {
          sideMenuCtrl._handleDrag(e);
          e.gesture.srcEvent.preventDefault();
        }, $element);
        $ionicGesture.on('dragright', function(e) {
          sideMenuCtrl._handleDrag(e);
          e.gesture.srcEvent.preventDefault();
        }, $element);
        $ionicGesture.on('release', function(e) {
          sideMenuCtrl._endDrag(e);
        }, $element);
        $scope.sideMenuDelegate = $ionicSideMenuDelegate;
        $scope.$watch('sideMenuDelegate.getOpenRatio()', function(ratio) {
          if (Math.abs(ratio)<1) {
            $element[0].style.zIndex = "1";
            $element[0].style.opacity = 0.7-Math.abs(ratio);
          } else {
            $element[0].style.zIndex = "-1";
          }
        });
      }
    }
  })

  .directive('canDragMenu', function ($timeout, $ionicGesture, $ionicSideMenuDelegate) {
    return {
      restrict: 'A',
      require: '^ionSideMenus',
      scope: true,
      link: function($scope, $element, $attr, sideMenuCtrl) {
        $ionicGesture.on('dragleft', function(e) {
          sideMenuCtrl._handleDrag(e);
          e.gesture.srcEvent.preventDefault();
        }, $element);
        $ionicGesture.on('dragright', function(e) {
          sideMenuCtrl._handleDrag(e);
          e.gesture.srcEvent.preventDefault();
        }, $element);
        $ionicGesture.on('release', function(e) {
          sideMenuCtrl._endDrag(e);
        }, $element);
      }
    }
  })

.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider

    .state('app', {
    url: '/app',
    abstract: true,
    templateUrl: 'templates/menu.html',
    controller: 'AppCtrl'
  })

  .state('app.search', {
    url: '/search',
    views: {
      'menuContent': {
        templateUrl: 'templates/search.html'
      }
    }
  })

  .state('app.browse', {
      url: '/browse',
      views: {
        'menuContent': {
          templateUrl: 'templates/browse.html'
        }
      }
    })
    .state('app.playlists', {
      url: '/playlists',
      views: {
        'menuContent': {
          templateUrl: 'templates/playlists.html',
          controller: 'PlaylistsCtrl'
        }
      }
    })

  .state('app.single', {
    url: '/playlists/:playlistId',
    views: {
      'menuContent': {
        templateUrl: 'templates/playlist.html',
        controller: 'PlaylistCtrl'
      }
    }
  });
  // if none of the above states are matched, use this as the fallback
  $urlRouterProvider.otherwise('/app/playlists');

});

我尝试了许多排列&amp;组合,但我没有得到如何实现这一目标。

需要一些帮助。

此致

0 个答案:

没有答案