Angular實現(xiàn)的進度條功能示例
本文實例講述了Angular實現(xiàn)的進度條功能。分享給大家供大家參考,具體如下:
項目里需要一個進度條,所以就在網(wǎng)上查找資料學習,看到了網(wǎng)友“雪狼”的代碼分享,寫的很高明,很精練,很厲害,原文中的代碼如下:
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;
});
這里結(jié)合自己的項目需要,自己改編了個簡單的進度條,可以加在項目里面,進度條的開始和結(jié)束由自己決定。
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>
更多關(guān)于AngularJS相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《AngularJS指令操作技巧總結(jié)》、《AngularJS入門與進階教程》及《AngularJS MVC架構(gòu)總結(jié)》
希望本文所述對大家AngularJS程序設(shè)計有所幫助。
相關(guān)文章
基于AngularJS+HTML+Groovy實現(xiàn)登錄功能
AngularJS是一款客戶端MVC的javascript框架,而客戶端MVC代表未來架構(gòu)(為什么要使用MVC+REST+CQRS架構(gòu)),如果你有Struts或SpringMVC等后端MVC框架編程經(jīng)驗,學習Angular會很快,基本是按照同一個MVC思路實現(xiàn)的,本文給大家介紹AngularJS+HTML+Groovy實現(xiàn)登錄功能2016-02-02
Angular2 組件間通過@Input @Output通訊示例
本篇文章主要介紹了Angular2 組件間通過@Input @Output通訊示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-08-08
AngularJS實現(xiàn)單獨作用域內(nèi)的數(shù)據(jù)操作
這篇文章給大家介紹了利用AngularJs如何實現(xiàn)ng-repeat內(nèi)各個小的子作用域單獨數(shù)據(jù)綁定。有需要的小伙伴們可以參考借鑒,下面來一起看看吧。2016-09-09
AngularJS模糊查詢功能實現(xiàn)代碼(過濾內(nèi)容下拉菜單排序過濾敏感字符驗證判斷后添加表格信息)
最近做項目遇到這樣的需求,要求添加球員的功能,具體樣式?jīng)]做具體要求,下面小編給大家?guī)砹薃ngularJS模糊查詢功能實現(xiàn)代碼(過濾內(nèi)容下拉菜單排序過濾敏感字符驗證判斷后添加表格信息),感興趣的朋友一起看看吧2017-10-10
AngularJs用戶登錄問題處理(交互及驗證、阻止FQ處理)
這篇文章主要為大家詳細介紹了AngularJs用戶登錄問題處理,包括交互及驗證、阻止FQ處理,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-10-10
淺談angular4 ng-content 中隱藏的內(nèi)容
本篇文章主要介紹了淺談angular4 ng-content 中隱藏的內(nèi)容,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-08-08

