Skip to content

Commit

Permalink
添加progress bar控件
Browse files Browse the repository at this point in the history
  • Loading branch information
hbcui1984 committed Apr 15, 2016
1 parent dd665f4 commit 352b30d
Show file tree
Hide file tree
Showing 13 changed files with 845 additions and 4 deletions.
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ module.exports = function(grunt) {
'js/mui.dialog.prompt.js',
'js/mui.dialog.toast.js',
'js/mui.popup.js',
'js/mui.progressbar.js',
'js/input.plugin.js',
'js/mui.number.js'

Expand Down
167 changes: 167 additions & 0 deletions dist/css/mui.css
Original file line number Diff line number Diff line change
Expand Up @@ -3892,6 +3892,173 @@ select:focus
transform: translate3d(-50%, -50%, 0) scale(1);
}

/* === Progress Bar === */
.mui-progressbar
{
position: relative;

display: block;
overflow: hidden;

width: 100%;
height: 2px;

-webkit-transform-origin: center top;
transform-origin: center top;
vertical-align: middle;

border-radius: 2px;
background: #b6b6b6;

-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.mui-progressbar span
{
position: absolute;
top: 0;
left: 0;

width: 100%;
height: 100%;

-webkit-transition: 150ms;
transition: 150ms;
-webkit-transform: translate3d(-100%, 0, 0);
transform: translate3d(-100%, 0, 0);

background: #007aff;
}
.mui-progressbar.mui-progressbar-infinite:before
{
position: absolute;
top: 0;
left: 0;

width: 100%;
height: 100%;

content: '';
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
-webkit-transform-origin: left center;
transform-origin: left center;
-webkit-animation: mui-progressbar-infinite 1s linear infinite;
animation: mui-progressbar-infinite 1s linear infinite;

background: #007aff;
}

body > .mui-progressbar
{
position: absolute;
z-index: 10000;
top: 0;
left: 0;

border-radius: 0;
}

.mui-progressbar-in
{
-webkit-animation: mui-progressbar-in 300ms forwards;
animation: mui-progressbar-in 300ms forwards;
}

.mui-progressbar-out
{
-webkit-animation: mui-progressbar-out 300ms forwards;
animation: mui-progressbar-out 300ms forwards;
}

@-webkit-keyframes mui-progressbar-in
{
from
{
-webkit-transform: scaleY(0);

opacity: 0;
}

to
{
-webkit-transform: scaleY(1);

opacity: 1;
}
}
@keyframes mui-progressbar-in
{
from
{
transform: scaleY(0);

opacity: 0;
}

to
{
transform: scaleY(1);

opacity: 1;
}
}
@-webkit-keyframes mui-progressbar-out
{
from
{
-webkit-transform: scaleY(1);

opacity: 1;
}

to
{
-webkit-transform: scaleY(0);

opacity: 0;
}
}
@keyframes mui-progressbar-out
{
from
{
transform: scaleY(1);

opacity: 1;
}

to
{
transform: scaleY(0);

opacity: 0;
}
}
@-webkit-keyframes mui-progressbar-infinite
{
0%
{
-webkit-transform: translate3d(-50%, 0, 0) scaleX(.5);
}

100%
{
-webkit-transform: translate3d(100%, 0, 0) scaleX(.5);
}
}
@keyframes mui-progressbar-infinite
{
0%
{
transform: translate3d(-50%, 0, 0) scaleX(.5);
}

100%
{
transform: translate3d(100%, 0, 0) scaleX(.5);
}
}
.mui-pagination
{
display: inline-block;
Expand Down
2 changes: 1 addition & 1 deletion dist/css/mui.min.css

Large diffs are not rendered by default.

144 changes: 144 additions & 0 deletions dist/js/mui.js
Original file line number Diff line number Diff line change
Expand Up @@ -7180,6 +7180,150 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
$.confirm = createConfirm;
$.prompt = createPrompt;
})(mui, window, document);
(function($, document) {
var CLASS_PROGRESSBAR = 'mui-progressbar';
var CLASS_PROGRESSBAR_IN = 'mui-progressbar-in';
var CLASS_PROGRESSBAR_OUT = 'mui-progressbar-out';
var CLASS_PROGRESSBAR_INFINITE = 'mui-progressbar-infinite';

var SELECTOR_PROGRESSBAR = '.mui-progressbar';

var _findProgressbar = function(container) {
container = $(container || 'body');
if (container.length === 0) return;
container = container[0];
if (container.classList.contains(CLASS_PROGRESSBAR)) {
return container;
}
var progressbars = container.querySelectorAll(SELECTOR_PROGRESSBAR);
if (progressbars) {
for (var i = 0, len = progressbars.length; i < len; i++) {
var progressbar = progressbars[i];
if (progressbar.parentNode === container) {
return progressbar;
}
}
}
};
/**
* 创建并显示进度条
* @param {Object} container 可选,默认body,支持selector,DOM Node,mui wrapper
* @param {Object} progress 可选,undefined表示循环,数字表示具体进度
* @param {Object} color 可选,指定颜色样式(目前暂未提供实际样式,可暂时不暴露此参数)
*/
var showProgressbar = function(container, progress, color) {
if (typeof container === 'number') {
color = progress;
progress = container;
container = 'body';
}
container = $(container || 'body');
if (container.length === 0) return;
container = container[0];
var progressbar;
if (container.classList.contains(CLASS_PROGRESSBAR)) {
progressbar = container;
} else {
var progressbars = container.querySelectorAll(SELECTOR_PROGRESSBAR + ':not(.' + CLASS_PROGRESSBAR_OUT + ')');
if (progressbars) {
for (var i = 0, len = progressbars.length; i < len; i++) {
var _progressbar = progressbars[i];
if (_progressbar.parentNode === container) {
progressbar = _progressbar;
break;
}
}
}
if (!progressbar) {
progressbar = document.createElement('span');
progressbar.className = CLASS_PROGRESSBAR + ' ' + CLASS_PROGRESSBAR_IN + (typeof progress !== 'undefined' ? '' : (' ' + CLASS_PROGRESSBAR_INFINITE)) + (color ? (' ' + CLASS_PROGRESSBAR + '-' + color) : '');
if (typeof progress !== 'undefined') {
progressbar.innerHTML = '<span></span>';
}
container.appendChild(progressbar);
}
}
if (progress) $.setProgressbar(container, progress);
return progressbar;
};
/**
* 关闭进度条
* @param {Object} container 可选,默认body,支持selector,DOM Node,mui wrapper
*/
var hideProgressbar = function(container) {
var progressbar = _findProgressbar(container);
if (!progressbar) {
return;
}
var classList = progressbar.classList;
if (!classList.contains(CLASS_PROGRESSBAR_IN) || classList.contains(CLASS_PROGRESSBAR_OUT)) {
return;
}
classList.remove(CLASS_PROGRESSBAR_IN);
classList.add(CLASS_PROGRESSBAR_OUT);
progressbar.addEventListener('webkitAnimationEnd', function() {
progressbar.parentNode && progressbar.parentNode.removeChild(progressbar);
progressbar = null;
});
return;
};
/**
* 设置指定进度条进度
* @param {Object} container 可选,默认body,支持selector,DOM Node,mui wrapper
* @param {Object} progress 可选,默认0 取值范围[0-100]
* @param {Object} speed 进度条动画时间
*/
var setProgressbar = function(container, progress, speed) {
if (typeof container === 'number') {
speed = progress;
progress = container;
container = false;
}
var progressbar = _findProgressbar(container);
if (!progressbar || progressbar.classList.contains(CLASS_PROGRESSBAR_INFINITE)) {
return;
}
if (progress) progress = Math.min(Math.max(progress, 0), 100);
var clientLeft = progressbar.clientLeft;
var span = progressbar.querySelector('span');
if (span) {
var style = span.style;
style.webkitTransform = 'translate3d(' + (-100 + progress) + '%,0,0)';
if (typeof speed !== 'undefined') {
style.webkitTransitionDuration = speed + 'ms';
} else {
style.webkitTransitionDuration = '';
}
}
return progressbar;
};
$.fn.progressbar = function(options) {
var progressbarApis = [];
options = options || {};
this.each(function() {
var self = this;
var progressbarApi = self.mui_plugin_progressbar;
if (!progressbarApi) {
self.mui_plugin_progressbar = progressbarApi = {
show: function() {
return showProgressbar(self, options.progress, options.color);
},
setProgress: function(progress) {
return setProgressbar(self, progress);
},
hide: function() {
return hideProgressbar(self);
}
};
}
progressbarApis.push(progressbarApi);
});
return progressbarApis.length === 1 ? progressbarApis[0] : progressbarApis;
};
// $.setProgressbar = setProgressbar;
// $.showProgressbar = showProgressbar;
// $.hideProgressbar = hideProgressbar;
})(mui, document);
/**
* Input(TODO resize)
* @param {type} $
Expand Down
2 changes: 1 addition & 1 deletion dist/js/mui.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/hello-mui/css/mui.min.css

Large diffs are not rendered by default.

Loading

0 comments on commit 352b30d

Please sign in to comment.