-
Notifications
You must be signed in to change notification settings - Fork 0
/
Drop File.html
51 lines (51 loc) · 1.33 KB
/
Drop 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Drop File</title>
<style>
#dropHere {
display: flex;
justify-content: center;
align-items: center;
margin: 5vmin auto;
width: 50vmin;
height: 50vmin;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
border: 3px solid black;
border-radius: 5vmin;
}
</style>
</head>
<body>
<div id="dropHere">
<span>↓ 拖到这儿 ↓</span>
</div>
</body>
<script>
var dropEle = document.getElementById('dropHere');
dropEle.ondragenter = function (e) {
return false;
};
dropEle.ondragover = function (e) {
return false;
};
dropEle.ondrop = function (e) {
showImage(e.dataTransfer.files[0]);
return false;
};
function showImage(data) {
var reader = new FileReader();
reader.readAsDataURL(data);
reader.onprogress = function (e) {
if (e.lengthComputable) {
dropEle.style.backgroundImage = 'url(' + e.target.result + ')';
}
};
}
</script>
</html>