Javascript 如何允许用户在ionic中更改应用程序背景色
如何允许用户在ionic中使用Angular更改应用程序颜色。例如,我想创建一个按钮,当它被单击时,它应该带来一个颜色下拉列表,当选择一种颜色时,它应该更改您可以使用的应用程序背景色 将Javascript 如何允许用户在ionic中更改应用程序背景色,javascript,angularjs,ionic-framework,Javascript,Angularjs,Ionic Framework,如何允许用户在ionic中使用Angular更改应用程序颜色。例如,我想创建一个按钮,当它被单击时,它应该带来一个颜色下拉列表,当选择一种颜色时,它应该更改您可以使用的应用程序背景色 将ng click=“selectTheme()”添加到您的按钮,并声明如下: .controller('yourCtrl', function($scope, $ionicPopup) { $scope.selectTheme = function() { $ionicPopup.show
ng click=“selectTheme()”
添加到您的按钮,并声明如下:
.controller('yourCtrl', function($scope, $ionicPopup) {
$scope.selectTheme = function() {
$ionicPopup.show({
title: 'Select Theme',
templateUrl: 'templates/select-theme.html',
scope: $scope,
buttons: [{ text: 'Ok' }],
});
});
$scope.themes = [
{ name: 'Theme 1', color: '#f00' },
{ name: 'Theme 2', color: '#0f0' },
{ name: 'Theme 3', color: '#00f' },
{ name: 'Theme 4', color: '#ff0' },
{ name: 'Theme 5', color: '#0ff' },
];
$scope.changeTheme = function (theme) {
$scope.bgColor = theme;
};
$scope.bgColor = $scope.themes[0]; // initial theme
})
然后,您可以创建一个列表,在模板/select theme.html
中选择颜色:
<div class="list card">
<div class="item" ng-repeat="theme in themes" ng-click="changeTheme(theme)">
<div class="color-ball" style="background-color:{{theme.color}}"></div>
<h2 ng-bind="theme.name"></h2>
<p ng-if="theme === bgColor">(Selected)</p>
</div>
</div>
然后,您只需要在
中设置style=“background color:{{{{bgColor.color}}”
希望有帮助。您可以使用
将ng click=“selectTheme()”
添加到您的按钮,并声明如下:
.controller('yourCtrl', function($scope, $ionicPopup) {
$scope.selectTheme = function() {
$ionicPopup.show({
title: 'Select Theme',
templateUrl: 'templates/select-theme.html',
scope: $scope,
buttons: [{ text: 'Ok' }],
});
});
$scope.themes = [
{ name: 'Theme 1', color: '#f00' },
{ name: 'Theme 2', color: '#0f0' },
{ name: 'Theme 3', color: '#00f' },
{ name: 'Theme 4', color: '#ff0' },
{ name: 'Theme 5', color: '#0ff' },
];
$scope.changeTheme = function (theme) {
$scope.bgColor = theme;
};
$scope.bgColor = $scope.themes[0]; // initial theme
})
然后,您可以创建一个列表,在模板/select theme.html
中选择颜色:
<div class="list card">
<div class="item" ng-repeat="theme in themes" ng-click="changeTheme(theme)">
<div class="color-ball" style="background-color:{{theme.color}}"></div>
<h2 ng-bind="theme.name"></h2>
<p ng-if="theme === bgColor">(Selected)</p>
</div>
</div>
然后,您只需要在
中设置style=“background color:{{{{bgColor.color}}”
希望有帮助。请让我知道我的答案是否对您有效。请让我知道我的答案是否对您有效。