这时我轻轻地闭上了眼睛,我好像来到童话世界,好像在和小鸟讨论秋天的美景,好像在和小草拍秋天的照片。农民伯伯在田野里收获了庄稼,果农们在果园里收获了果子,我们在学校里收获快乐、收获知识、收获成长。
本文实例讲述了Angular实现的进度条功能。分享给大家供大家参考,具体如下:
项目里需要一个进度条,所以就在网上查找资料学习,看到了网友“雪狼”的代码分享,写的很高明,很精练,很厉害,原文中的代码如下:
HTML部分:
<div ng-class="{progress: true, 'progress-striped': vm.striped}">
<div ng-class="['progress-bar', vm.style]" ng-style="{width: vm.value + '%'}">
<div ng-if="vm.showLabel">{{vm.value}}%</div>
</div>
</div>
<h3>选项</h3>
<label>进度:<input type="number" class="form-control" ng-model="vm.value"/></label>
<button class="btn btn-primary" ng-click="vm.value=0">0%</button>
<button class="btn btn-primary" ng-click="vm.value=20">20%</button>
<button class="btn btn-primary" ng-click="vm.value=60">60%</button>
<button class="btn btn-primary" ng-click="vm.value=100">100%</button>
<hr/>
<label>斑马纹<input type="checkbox" ng-model="vm.striped"/></label>
<label>文字<input type="checkbox" ng-model="vm.showLabel"/></label>
<hr/>
<label>风格:
<select ng-model="vm.style" class="form-control">
<option value="progress-bar-success">progress-bar-success</option>
<option value="progress-bar-info">progress-bar-info</option>
<option value="progress-bar-danger">progress-bar-danger</option>
<option value="progress-bar-warning">progress-bar-warning</option>
</select>
</label>
JS部分:
'use strict';
angular.module('ngShowcaseApp').controller('ctrl.show.progress', function ($scope) {
var vm = $scope.vm = {};
vm.value = 50;
vm.style = 'progress-bar-info';
vm.showLabel = true;
});
这里结合自己的项目需要,自己改编了个简单的进度条,可以加在项目里面,进度条的开始和结束由自己决定。
1. js代码
var myApp = angular.module('myApp', []);
myApp.controller('main', ['$scope', '$interval', function($scope, $interval){
var vm = $scope.vm = {};
vm.value = 0;
vm.style = 'progress-bar-danger';
vm.showLabel = true;
vm.striped = true;
$scope.selectValue = function (){
console.log(vm.style);
};
var index = 0;
var timeId = 500;
$scope.count = function(){
var start = $interval(function(){
vm.value = ++index;
if (index > 99) {
$interval.cancel(start);
}
if (index == 60) {
index = 99;
}
}, timeId);
};
}]);
2. html代码
<div ng-class="{progress: true, 'progress-striped': vm.striped}" class="col-md-4">
<div ng-class="['progress-bar', vm.style]" ng-style="{width: vm.value + '%'}">
<div ng-if="vm.showLabel">{{vm.value}}%</div>
</div>
</div>
<button class="btn btn-success" ng-click="count()">开始进度</button>
希望本文所述对大家AngularJS程序设计有所帮助。
以上就是Angular实现的进度条功能示例。付出才有回报。懂得付出,才能正确看待收获,才能懂得平和自我。付出越多收获才越大。唯有付出,才有收获。天下没有免费的午餐,每个人都要摒弃不劳而获的想法,只有勤奋可以改变命运。更多关于Angular实现的进度条功能示例请关注haodaima.com其它相关文章!