-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathdemo.html
142 lines (116 loc) · 3.04 KB
/
demo.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE html>
<html>
<head>
<title>html5 upload component</title>
<meta charset="utf-8" />
<style type="text/css" media="all">
body {
margin: 0;
padding: 0;
}
.wrapper {
margin: 20px 0;
padding: 0 20px;
}
#btn-upload {
display: block;
width: 150px;
height: 50px;
border: 1px solid #999999;
color: #666666;
font-size: 16px;
text-align: center;
line-height: 50px;
text-decoration: none;
position: relative;
overflow: hidden;
direction: 'ltr';
}
#btn-upload:hover {
background: #f3f3f3;
}
#select-file {
position: absolute;
top: 0;
right: 0;
font-size: 100px;
margin: 0;
padding: 0;
cursor: 'pointer';
opacity: 0;
}
.file-list {
margin: 20px 0 0 0;
}
.file {
padding: 10px 0;
font-size: 16px;
color: #666666;
line-height: 20px;
}
.file .size,
.file .progress {
font-size: 12px;
color: #999999;
margin: 0 0 0 5px;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="upload">
<a href="javascript:;" id="btn-upload">
<span>点击上传文件</span>
<input type="file" id="select-file" multiple/>
</a>
</div>
<div class="file-list">
</div>
</div>
<script type="text/html" id="tpl-file">
<div class="file">
<span class="name"></span>
<span class="size"></span>
<span class="progress">0%</span>
</div>
</script>
<script type="text/javascript" src="node_modules/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="node_modules/simple-module/dist/simple-module.js"></script>
<script type="text/javascript" src="dist/simple-uploader.js"></script>
<script type="text/javascript">
$(function() {
var uploader = new SimpleUploader({
url: '/upload'
});
uploader.on('beforeupload', function(e, file) {
var $list = $('.file-list');
var $file = $($('#tpl-file').html());
$file.attr('id', 'file-' + file.id);
$file.find('.name').text(file.name);
$file.find('.size').text((file.size / 1000) + 'KB');
$file.appendTo($list);
});
uploader.on('uploadprogress', function(e, file, loaded, total) {
var $file = $('#file-' + file.id);
$file.find('.progress').text((loaded / total * 100).toFixed(0) + '%');
});
uploader.on('uploadsuccess', function(e, file, result) {
var $file = $('#file-' + file.id);
$file.find('.progress').remove();
});
resetFileSelect();
function resetFileSelect() {
var $file = $('#select-file');
if ($file.val()) {
$file = $file.clone().replaceAll($file);
}
$file.off('change').on('change', function(e) {
var $file = $(this);
uploader.upload(this);
resetFileSelect();
});
}
});
</script>
</body>
</html>