博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
angular-loading用法以及注意事项
阅读量:4646 次
发布时间:2019-06-09

本文共 9304 字,大约阅读时间需要 31 分钟。

css
.dw-loading {
position: absolute; top: 0; left: 0; right: 0; bottom: 0; text-align: center; display: none;}.dw-loading:before {
content: ''; display: inline-block; height: 100%; vertical-align: middle;}.dw-loading.dw-loading-active {
display: block;}.dw-loading.dw-loading-overlay {
background-color: rgba(255, 255, 255, .7); z-index: 9999;}.dw-loading > .dw-loading-body {
display: inline-block; vertical-align: middle; position: relative;}.dw-loading > .dw-loading-body > .dw-loading-spinner {
position: relative;}.dw-loading > .dw-loading-body > .dw-loading-text {
position: relative; top: 25px; font-weight: bold; font-size: 11px; text-shadow: 0 0 2px rgb(255, 255, 255);}
--js--
(function (window, angular, undefined) {  'use strict';  angular.module('darthwade.dwLoading', [])    .value('dwLoadingOptions', {      active: false,      text: 'Loading...',      className: '',      overlay: true,      spinner: true,      spinnerOptions: {        lines: 12,            // The number of lines to draw        length: 7,            // The length of each line        width: 4,             // The line thickness        radius: 10,           // The radius of the inner circle        rotate: 0,            // Rotation offset        corners: 1,           // Roundness (0..1)        color: '#000',        // #rgb or #rrggbb        direction: 1,         // 1: clockwise, -1: counterclockwise        speed: 2,             // Rounds per second        trail: 100,           // Afterglow percentage        opacity: 1/4,         // Opacity of the lines        fps: 20,              // Frames per second when using setTimeout()        zIndex: 2e9,          // Use a high z-index by default        className: 'dw-spinner', // CSS class to assign to the element        top: 'auto',          // center vertically        left: 'auto',         // center horizontally        position: 'relative'  // element position      }    })    .service('dwLoading', ['$rootScope', 'dwLoadingOptions', function ($rootScope, dwLoadingOptions) {      var self = this;      /**       * Sets default options (@see `dwLoadingOptions`)       * @param {object} options       */      self.setDefaultOptions = function (options) {        extend(true, dwLoadingOptions, options);      };      /**       * Activates spinner by key       * @param {string} key       */      self.start = function (key) {        $rootScope.$broadcast('$dwLoadingStart', key);      };      /**       * Deactivates spinner by key       * @param {string} key       */      self.finish = function (key) {        $rootScope.$broadcast('$dwLoadingFinish', key);      };    }])    // Shortcut    .factory('$loading', ['dwLoading', function(dwLoading) {      return dwLoading;    }])    .directive('dwLoading', ['$window', '$compile', 'dwLoadingOptions', function ($window, $compile, dwLoadingOptions) {      return {        scope: true,        link: function (scope, element, attrs) {          scope.spinner = null;          scope.key = attrs.dwLoading || false;          /**           * Starts spinner           */          scope.start = function () {            if (scope.container) {              scope.container.addClass('dw-loading-active');            }            if (scope.spinner) {              scope.spinner.spin(scope.spinnerContainer[0]);            }          };          /**           * Stops spinner           */          scope.finish = function () {            if (scope.container) {              scope.container.removeClass('dw-loading-active');            }            if (scope.spinner) {              scope.spinner.stop();            }          };                    scope.$watch(attrs.dwLoadingOptions, function (options) {            scope.finish();            scope.options = extend(true, {}, dwLoadingOptions, options);            // Build template            var body = angular.element('
') .addClass('dw-loading-body'); scope.container = angular.element('
') .addClass('dw-loading') .append(body); if (scope.options.overlay) { scope.container.addClass('dw-loading-overlay'); } if (scope.options.className) { scope.container.addClass(scope.options.className); } if (scope.options.spinner) { scope.spinnerContainer = angular.element('
') .addClass('dw-loading-spinner'); body.append(scope.spinnerContainer); scope.spinner = new $window.Spinner(scope.options.spinnerOptions); } if (scope.options.text) { var text = angular.element('
') .addClass('dw-loading-text') .text(scope.options.text); body.append(text); } element.append(scope.container);// $compile(container)(scope); if (scope.options.active || !scope.key) { scope.start(); } }, true); scope.$on('$dwLoadingStart', function (event, key) { if (key === scope.key) { scope.start(); } }); scope.$on('$dwLoadingFinish', function (event, key) { if (key === scope.key) { scope.finish(); } }); scope.$on('$destroy', function () { scope.finish(); scope.spinner = null; }); } }; }]); /** * Extends the destination object `dst` by copying all of the properties from the `src` object(s) * to `dst`. You can specify multiple `src` objects. * * @param {Boolean} deep If true, the merge becomes recursive (optional) * @param {Object} dst Destination object. * @param {Object} src Source object(s). * @returns {Object} Reference to `dst`. */ function extend(dst) { var deep = false, i = 1; if (typeof dst === 'boolean') { deep = dst; dst = arguments[1] || {}; i++; } angular.forEach([].slice.call(arguments, i), function (obj) { var array, clone, copy, key, src; for (key in obj) { src = dst[key]; copy = obj[key]; if (dst === copy) { continue; } if (deep && copy && (angular.isObject(copy) || (array = angular.isArray(copy)))) { if (array) { clone = (src && angular.isArray(src)) ? src : []; } else { clone = (src && angular.isObject(src)) ? src : {}; } dst[key] = extend(deep, clone, copy); } else if (copy !== undefined) { dst[key] = copy; } } }); return dst; }})(window, window.angular);

 

--html--     Angular Block Spinner    
--js--

Basic

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

Autoload

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

No text, no overlay

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

Custom styling, custom spinner, custom text

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

如果 dw-loading="" 写在form上或者form的父级会导致 angularjs form表单验证失败 --参数--
dw-loading-options="";
{  active: false, // Defines current loading state  text: 'Loading...', // Display text className: '', // Custom class, added to directive overlay: true, // Display overlay spinner: true, // Display spinner spinnerOptions: { lines: 12, // The number of lines to draw length: 7, // The length of each line width: 4, // The line thickness radius: 10, // The radius of the inner circle rotate: 0, // Rotation offset corners: 1, // Roundness (0..1) color: '#000', // #rgb or #rrggbb direction: 1, // 1: clockwise, -1: counterclockwise speed: 2, // Rounds per second trail: 100, // Afterglow percentage opacity: 1 / 4, // Opacity of the lines fps: 20, // Frames per second when using setTimeout() zIndex: 2e9, // Use a high z-index by default className: 'dw-spinner', // CSS class to assign to the element top: 'auto', // Center vertically left: 'auto', // Center horizontally position: 'relative' // Element position } }

Content

 

转载于:https://www.cnblogs.com/yiyangl/p/10058540.html

你可能感兴趣的文章
POJ 2031 Building a Space Station
查看>>
面向对象1
查看>>
编程开发之--java多线程学习总结(5)
查看>>
register_globals(全局变量注册开关)
查看>>
as3调用外部swf里的类的方法
查看>>
如何让 zend studio 10 识别 Phalcon语法并且进行语法提示
查看>>
任意阶幻方(魔方矩阵)C语言实现
查看>>
视频教程--ASP.NET MVC 使用 Petapoco 微型ORM框架+NpgSql驱动连接 PostgreSQL数据库
查看>>
第五次作业
查看>>
织梦教程
查看>>
杭电多校 Harvest of Apples 莫队
查看>>
java 第11次作业:你能看懂就说明你理解了——this关键字
查看>>
C/C++心得-结构体
查看>>
函数名作为参数传递
查看>>
apt-get for ubuntu 工具简介
查看>>
数值计算算法-多项式插值算法的实现与分析
查看>>
day8-异常处理与网络编程
查看>>
Python基础-time and datetime
查看>>
Linux epoll 笔记(高并发事件处理机制)
查看>>
shell脚本练习01
查看>>