-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.html
90 lines (84 loc) · 2.33 KB
/
file.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>file</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references -->
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<style type="text/css">
* { margin:0; padding: 0}
.drop {
position: absolute;
top: 12.5%;
left: 25%;
width: 50%;
height: 25%;
border: 15px dashed #ccc;
}
.preview-list {
position: absolute;
width: 100%;
height: 50%;
left: 0;
bottom: 0;
border-top: 1px solid #ccc;
}
.preview {
float:left;
margin: 15px;
border: 1px solid black;
width: 300px;
height: 150px;
overflow-y: auto;
opacity: 0;
}
.preview img {
width: 100%;
}
</style>
</head>
<body>
<div class="drop"></div>
<div class="preview-list"></div>
<textarea class="preview-tpl" style="display: none; "><div class="preview"><img src="{src}" /></div></textarea>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var previewTpl = $('.preview-tpl').val();
$('.drop').on('dragover', function(e) {
e = e.originalEvent;
e.stopPropagation();
e.preventDefault();
e.dataTransfer.dropEffect = 'copy';
}).on('drop', function(e) {
e = e.originalEvent;
e.stopPropagation();
e.preventDefault();
var files = e.dataTransfer.files;
for(var i = 0; i < files.length; i++) {
var file = files[i];
var reader = new FileReader();
reader.onload = function(e) {
var data = {
src: e.target.result
};
var html = previewTpl.replace(/\{([\w]+)\}/gi, function(m, r) {
return data[r];
});
var el = $(html);
$('.preview-list').append(el);
el.fadeTo(500, 1);
};
reader.readAsDataURL(file);
}
});
});
</script>
</body>
</html>