Skip to content

Commit 4d14dfd

Browse files
author
cong.li
committed
添加拖拽文件的提示
1 parent b4b4c99 commit 4d14dfd

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

index.html

+23
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
border-radius: 20px;
1313
margin: 10px auto;
1414
padding: 20px;
15+
min-height: 200px;
1516
}
1617

1718
#drop-area.highlight {
@@ -39,6 +40,7 @@
3940
<body>
4041
<progress id="progress" value="0" max="100"></progress>
4142
<div id="drop-area">
43+
4244
<pre>
4345
{{range $href, $name := . }}
4446
<a href="{{$href}}">{{$name}}</a>
@@ -47,6 +49,27 @@
4749
<input type="file" id="fileElem" multiple accept="image/*" onchange="handleFiles(this.files)">
4850
</div>
4951
<script>
52+
53+
var div = document.getElementById('drop-area');
54+
var canvas = document.createElement('canvas');
55+
var ctx = canvas.getContext('2d');
56+
canvas.width = div.offsetWidth;
57+
canvas.height = div.offsetHeight;
58+
ctx.font = "40px Arial";
59+
ctx.fillStyle = "rgba(128, 128, 128, 0.5)";
60+
ctx.textAlign = "center";
61+
ctx.textBaseline = "middle";
62+
ctx.fillText("Drag & Drop a File", div.offsetWidth / 2, div.offsetHeight / 2);
63+
div.style.position = "relative";
64+
div.appendChild(canvas);
65+
canvas.style.position = "absolute";
66+
canvas.style.top = 0;
67+
canvas.style.left = 0;
68+
canvas.style.zIndex = -1;
69+
canvas.style.pointerEvents = "none";
70+
71+
72+
5073
let dropArea = document.getElementById("drop-area")
5174

5275
;['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {

0 commit comments

Comments
 (0)