-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
61 lines (54 loc) · 1.77 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Uploader</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
}
#preview {
display: flex;
gap: 10px;
margin-top: 20px;
}
img {
width: 100px;
height: 100px;
object-fit: cover;
border-radius: 8px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
}
</style>
</head>
<body>
<h1>Image Uploader</h1>
<button onclick="document.getElementById('fileInput').click()">Select Images</button>
<input type="file" id="fileInput" multiple accept="image/*" style="display: none" onchange="handleFiles(this.files)">
<div id="preview"></div>
<script>
// Array to store selected images
let selectedImages = [];
function handleFiles(files) {
selectedImages = Array.from(files); //Add images to array
displayPreview();
}
// Display image previews
function displayPreview() {
const preview = document.getElementById('preview');
preview.innerHTML = ""; // Clear previous images
selectedImages.forEach(file => {
const img = document.createElement('img');
img.src = URL.createObjectURL(file); // Create a temporary URL for the image
img.onload = () => URL.revokeObjectURL(img.src); // Clean up memory once the image loads
preview.appendChild(img);
});
}
</script>
</body>
</html>