<small>上拉菜單(ActionSheet)通過往上彈出的框,來讓用戶選擇選項婆瓜。
非常危險的選項會以高亮的紅色來讓人第一時間識別。你可以通過點擊取消按鈕或者點擊空白的地方來讓它消失。</small>
實例
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 代碼
<small>在代碼中觸發(fā)上拉菜單蟀瞧,需要在你的 angular 控制器中使用 $ionicActionSheet 服務(wù):</small>
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','$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() {
// add cancel code..
},
buttonClicked: function(index) {
return true;
}
});
$timeout(function() {
hideSheet();
}, 2000);
};
}])
嘗試一下 ?
<small>運行效果如下圖:</small>
ionic 背景層
<small>我們經(jīng)常需要在 UI 上,例如在彈出框条摸、加載框悦污、其他彈出層中顯示或隱藏背景層。
在組件中可以使用$ionicBackdrop.retain()來顯示背景層钉蒲,使用$ionicBackdrop.release()隱藏背景層切端。
每次調(diào)用retain后,背景會一直顯示顷啼,直到調(diào)用release消除背景層踏枣。</small>
實例
HTML 代碼
<body ng-app="starter" ng-controller="actionsheetCtl" >
<ion-pane>
<ion-content >
<h2 ng-click="action()">$ionicBackdrop</h2>
</ion-content>
</ion-pane>
</body>
JavaScript 代碼
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() { //默認(rèn)讓它1秒后消失
$ionicBackdrop.release();
}, 1000);
};
}])
嘗試一下 ?
顯示效果如下圖所示:
ionic 下拉刷新
<small>在加載新數(shù)據(jù)的時候,我們需要實現(xiàn)下拉刷新效果钙蒙,代碼如下:</small>
實例
HTML 代碼
<body ng-app="starter" ng-controller="actionsheetCtl" >
<ion-pane>
<ion-content >
<ion-refresher pulling-text="下拉刷新" on-refresh="doRefresh()">
</ion-refresher>
<ion-list>
<ion-item ng-repeat="item in items" ng-bind="item.name"></ion-item>
</ion-list>
</ion-content>
</ion-pane>
</body>
JavaScript 代碼
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' ,'$http',function($scope,$timeout,$http){
$scope.items=[
{
"name":"HTML5"
},
{
"name":"JavaScript"
},
{
"name":"Css3"
}
];
$scope.doRefresh = function() {
$http.get('http://www.runoob.com/try/demo_source/item.json') //注意改為自己本站的地址茵瀑,不然會有跨域問題
.success(function(newItems) {
$scope.items = newItems;
})
.finally(function() {
$scope.$broadcast('scroll.refreshComplete');
});
};
}])
item.json 文件數(shù)據(jù):
[
{
"name":"菜鳥教程"
},
{
"name":"www.runoob.com"
}
]
嘗試一下 ?
效果如下所示:
![Uploading Paste_Image_396445.png . . .]