-
Notifications
You must be signed in to change notification settings - Fork 0
/
progress.html
98 lines (87 loc) · 2.67 KB
/
progress.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>progress</title>
<style>
.progress {
height: 20px;
width: 100%;
border: 1px solid #ddd;
background: #fff;
}
.progress-bar {
height: 20px;
background: #dd0;
text-align: center;
}
</style>
</head>
<body>
<div class="progress" data-snake="progress" data-progress="10">
<div class="progress-bar" style="width: 0%;">
<span class="progress-number">0</span>%
</div>
</div>
<div id="progress" class="progress" data-snake="progress">
<div class="progress-bar" style="width: 0%;">
<span class="progress-number">0</span>%
</div>
</div>
<button id="test-btn">增加</button>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
(function($) {
function Progress(ele, option) {
this.$ele = $(ele);
this.progress = option.progress || 0;
this.init();
}
Progress.DEFAULTS = {
progress: 0
};
Progress.prototype.init = function() {
var self = this;
this.updataProgress(Number(self.progress));
};
Progress.prototype.updataProgress = function(progress) {
var self = this;
self.$ele.find('.progress-bar').animate({
width: progress + "%"
});
self.$ele.find(".progress-number").text(progress);
}
function Plugin(option) {
return this.each(function() {
var $this = $(this);
var data = $(this).data("snake.progress");
var options = $.extend({}, $.extend(Progress.DEFAULTS), $this.data(), typeof option == "object" && option);
if (!data) $this.data("snake.progress", (data = new Progress(this, options)))
if (typeof option == "number") {
data.updataProgress(option);
}
});
}
var old = $.fn.dropdown
$.fn.progress = Plugin
$.fn.progress.Constructor = Progress
// DROPDOWN NO CONFLICT
// ====================
$.fn.progress.noConflict = function() {
$.fn.dropdown = old
return this
}
$(window).on("load", function() {
$("[data-snake='progress'").each(function() {
Plugin.call($(this), $(this).data());
});
});
})(jQuery);
</script>
<script>
$("#test-btn").on("click", function() {
$("#progress").progress(50);
});
</script>
</body>
</html>