Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

The ionic background layer


May 21, 2021 ionic



The ionic background layer

We often need to display or hide background layers on the UI, such as pop-ups, load boxes, or other pop-up layers.

In the component, you can use $ionicBackdrop.retain() to display the background layer, and $ionicBackdrop.release() to hide the background layer.

After each call to retain, the background is displayed until the release is called to eliminate the background layer.


HTML code

<body ng-app="starter" ng-controller="actionsheetCtl" >
	<ion-pane>
	    <ion-content >
	        <h2 ng-click="action()">$ionicBackdrop</h2>
	    </ion-content>
	</ion-pane>
</body>

JavaScript code

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

.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);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})

.controller( 'actionsheetCtl',['$scope','$timeout' ,'$ionicBackdrop',function($scope,$timeout,$ionicBackdrop){

    $scope.action = function() {
       $ionicBackdrop.retain();
       $timeout(function() {    //默认让它1秒后消失
         $ionicBackdrop.release();
       }, 1000);
    }; 
}])

Try it out . . .

The display looks like this:

The ionic background layer