Click heresee demo
- simple and easy to use, the same UI with MS Word 2013;
- added "Latest Used Color" feature;
- user could use "more color" feature in browsers supported HTML5 API
input[type='color']
; - support multi-language, current support: Simplified-Chinese(default)[zh-cn], American-English[en-us];
you could download this repository, and use the compressed css and js file. For convenience, you could also use it by installing bower package via bower install color-picker
.
color-picker is based on angular,
example:
<link rel="stylesheet" href="path/to/color-picker.min.css">
<script src="path/to/angular.js"></script>
<script src="path/to/color-picker.min.js"></script>
<!-- directive way -->
<font-color></font-color>
<!-- controller way -->
<div ng-controller="demoCtrl">
<div color-picker set-color="dynamicSetColor()" class="font-color" ng-style="{'background-color': selectedForeColor}"></div>
</div>
<script>
var myApp = angular.module('colorpickerDemo', ['ui.colorpicker']);
// directive way
myApp.directive('fontColor', function() {
return {
restrict: 'E',
scope:{},
replace: false,
template: '<div color-picker default-color="#ff0000" class="font-color" ng-style="{\'background-color\': selectedFontColor}"></div>',
link: function(scope) {
scope.selectedFontColor = '#f00';
scope.$on('colorPicked', function(event, color) {
scope.selectedFontColor = color;
});
}
}
})
// controller way
myApp.controller('demoCtrl', function($scope) {
$scope.selectedForeColor = dynamicSetColor();
$scope.$on('colorPicked', function(event, color) {
$scope.selectedForeColor = color;
});
// dynamically set color
$scope.dynamicSetColor = dynamicSetColor;
function dynamicSetColor() {
return '#0f0';
}
});
</script>
The default language is Simplified Chinese(zh-cn
), we also provide American English(en-us
), you could configure like below:
angular.module('colorpickerDemo', ['ui.colorpicker'])
.config(function (localizeProvider) {
localizeProvider.setDefaultLang('en-us');
})
The source code of language is src/lang.service.js
, pull request is welcome to support more languages.
you could set below attributes to configure color-picker:
default-color
: default color you want to set,eg.default-color="#ff0000"
disabled
: if is disabled, egdisabled="disabled"
set-color
: the function to dynamically set default color, to archive the goal of setting different default color in different context eg.set-color="dynamicSet()"
, anddynamicSet
function returns the color depends on different context.
colorPicked
: triggered after use selecting a color, it could be listened in the parent scope of color-picker, the event parameters include a key color
which is user selected