2
我試圖更改字體和確切文本的字體大小,我更改了字體部分並更改了大小,但更改爲兩個不同的文本。我如何將這兩個函數應用於文本。帶有AngularJS的文本大小滑塊
這是我的HTML
<div ng-controller="StylesCtrl">
<select ng-model="font" ng-options="font as font.label for font in fonts" ng-change="change(font)"></select>
<h3><font face="{{selectedFont}}">Text Is</font></h3>
</div>
<text-size-slider min="12" max="24" unit="px" value="18"></text-size-slider>
<div>Font Size Slider</div>
這是我的腳本文件
(function() {
angular.module('appBuilderApp').controller("StylesCtrl", function ($scope) {
$scope.fonts = [
{
value: 'Arial',
label: 'Arial'
},
{
value: 'Tahoma',
label: 'Tahoma'
}
];
$scope.selectedFont = '';
$scope.change = function (option) {
$scope.selectedFont = option.value;
}
});
angular.module('appBuilderApp').directive('textSizeSlider', ['$document', function ($document) {
return {
restrict: 'E',
template: '<div class="text-size-slider"><span class="small-letter" ng-style="{ fontSize: min + unit }">A</span> <input type="range" min="{{ min }}" max="{{ max }}" step="{{ step || 0 }}" ng-model="textSize" class="slider" value="{{ value }}" /> <span class="big-letter" ng-style="{ fontSize: max + unit }">A</span></div>',
scope: {
min: '@',
max: '@',
unit: '@',
value: '@',
step: '@'
},
link: function (scope, element, attr) {
scope.textSize = scope.value;
scope.$watch('textSize', function (size) {
$document[0].body.style.fontSize = size + scope.unit;
});
}
}
}]);
})();
請幫我兩者的功能應用到一個文本。
謝謝,這對我很好。 :) – shamila