-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupload.js
31 lines (22 loc) · 842 Bytes
/
upload.js
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
jQuery('input[type=file]').change(function(e) {
if(typeof FileReader == "undefined") return true;
var elem = jQuery(this);
var files = e.target.files;
for ( var i = 0, f; f = files[i]; i++ ) {
if ( f.type.match('image.*') ) {
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
var image = e.target.result;
previewDiv = jQuery('.thumb', elem.parent() );
bg_width = previewDiv.width() * 2;
previewDiv.css({
"background-size" : "cover",
"background-image" : "url("+image+")",
});
};
})(f);
reader.readAsDataURL(f);
}
}
});