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>
更多關于AngularJS相關內(nèi)容感興趣的讀者可查看本站專題:《AngularJS指令操作技巧總結(jié)》、《AngularJS入門與進階教程》及《AngularJS MVC架構(gòu)總結(jié)》
希望本文所述對大家AngularJS程序設計有所幫助。
相關文章
AngularJS深入探討scope,繼承結(jié)構(gòu),事件系統(tǒng)和生命周期
這篇文章主要介紹了AngularJS的scope,繼承結(jié)構(gòu),事件系統(tǒng)和生命周期,較為詳細的分析了scope的作用域、層次結(jié)構(gòu)、繼承及生命周期相關概念與使用技巧,需要的朋友可以參考下2016-11-11Angular2使用Angular-CLI快速搭建工程(二)
這篇文章主要介紹了Angular2使用Angular-CLI快速搭建工程(二),具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-05-05Angular的FormArray和模態(tài)框結(jié)合使用實例詳解
這篇文章主要為大家介紹了Angular的FormArray和模態(tài)框結(jié)合使用實例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-11-11Angular使用$http.jsonp發(fā)送跨站請求的方法
這篇文章主要介紹了Angular使用$http.jsonp發(fā)送跨站請求的方法,結(jié)合實例形式分析了$http.jsonp發(fā)送跨站請求遇到的問題與相應的解決方法,具有一定參考借鑒價值,需要的朋友可以參考下2017-03-03