pakdeveloper commited on
Commit
fe56745
·
verified ·
1 Parent(s): 7bfbf7a

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +156 -4
index.html CHANGED
@@ -3,21 +3,173 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Image Gallery</title>
7
- <link rel="stylesheet" href="styles.css">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  </head>
9
  <body>
10
  <div class="container">
11
- <h1>Drag & Drop Image Gallery</h1>
 
 
 
 
 
12
  <div id="drop-area">
13
  <p>Drag & Drop your images here</p>
14
  <p>or</p>
15
  <button id="file-input-button">Upload Files</button>
16
  <input type="file" id="file-input" multiple accept="image/*" style="display: none;">
17
  </div>
 
 
18
  <div id="gallery" class="gallery"></div>
19
  </div>
20
 
21
- <script src="script.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  </body>
23
  </html>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Image Upload Script</title>
7
+ <style>
8
+ /* General Styles */
9
+ * {
10
+ margin: 0;
11
+ padding: 0;
12
+ box-sizing: border-box;
13
+ }
14
+
15
+ body {
16
+ background-color: white;
17
+ font-family: Arial, sans-serif;
18
+ display: flex;
19
+ justify-content: center;
20
+ align-items: center;
21
+ height: 100vh;
22
+ }
23
+
24
+ .container {
25
+ text-align: center;
26
+ width: 90%;
27
+ max-width: 1255px;
28
+ }
29
+
30
+ /* Header Image */
31
+ .header img {
32
+ width: 100%;
33
+ height: auto;
34
+ max-width: 1255px;
35
+ margin-bottom: 20px;
36
+ }
37
+
38
+ /* Drop Area */
39
+ #drop-area {
40
+ border: 2px dashed #ccc;
41
+ border-radius: 10px;
42
+ padding: 20px;
43
+ margin: 20px auto;
44
+ background-color: #fff;
45
+ transition: background-color 0.3s ease;
46
+ }
47
+
48
+ #drop-area:hover {
49
+ background-color: #f0f0f0;
50
+ }
51
+
52
+ #drop-area p {
53
+ margin: 10px 0;
54
+ font-size: 18px;
55
+ color: #333;
56
+ }
57
+
58
+ #file-input-button {
59
+ padding: 10px 20px;
60
+ background-color: #007bff;
61
+ color: white;
62
+ border: none;
63
+ border-radius: 5px;
64
+ cursor: pointer;
65
+ font-size: 16px;
66
+ }
67
+
68
+ #file-input-button:hover {
69
+ background-color: #0056b3;
70
+ }
71
+
72
+ /* Gallery */
73
+ .gallery {
74
+ display: grid;
75
+ grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
76
+ gap: 10px;
77
+ margin-top: 20px;
78
+ }
79
+
80
+ .gallery img {
81
+ width: 100%;
82
+ height: auto;
83
+ border-radius: 10px;
84
+ object-fit: cover;
85
+ }
86
+ </style>
87
  </head>
88
  <body>
89
  <div class="container">
90
+ <!-- Header Image -->
91
+ <div class="header">
92
+ <img src="https://huggingface.co/spaces/pakdeveloper/Static-002/resolve/main/imageuploadscript.png" alt="Image Upload Script" width="1255">
93
+ </div>
94
+
95
+ <!-- Drag & Drop Area -->
96
  <div id="drop-area">
97
  <p>Drag & Drop your images here</p>
98
  <p>or</p>
99
  <button id="file-input-button">Upload Files</button>
100
  <input type="file" id="file-input" multiple accept="image/*" style="display: none;">
101
  </div>
102
+
103
+ <!-- Image Gallery -->
104
  <div id="gallery" class="gallery"></div>
105
  </div>
106
 
107
+ <script>
108
+ document.addEventListener("DOMContentLoaded", () => {
109
+ const dropArea = document.getElementById('drop-area');
110
+ const fileInput = document.getElementById('file-input');
111
+ const gallery = document.getElementById('gallery');
112
+
113
+ // Prevent default drag behaviors
114
+ ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
115
+ dropArea.addEventListener(eventName, preventDefaults, false);
116
+ });
117
+
118
+ function preventDefaults(e) {
119
+ e.preventDefault();
120
+ e.stopPropagation();
121
+ }
122
+
123
+ // Highlight drop area when item is dragged over it
124
+ ['dragenter', 'dragover'].forEach(eventName => {
125
+ dropArea.addEventListener(eventName, () => dropArea.classList.add('highlight'), false);
126
+ });
127
+
128
+ ['dragleave', 'drop'].forEach(eventName => {
129
+ dropArea.addEventListener(eventName, () => dropArea.classList.remove('highlight'), false);
130
+ });
131
+
132
+ // Handle dropped files
133
+ dropArea.addEventListener('drop', handleDrop, false);
134
+
135
+ function handleDrop(e) {
136
+ const dt = e.dataTransfer;
137
+ const files = dt.files;
138
+
139
+ handleFiles(files);
140
+ }
141
+
142
+ // Open file input when the button is clicked
143
+ document.getElementById('file-input-button').addEventListener('click', () => {
144
+ fileInput.click();
145
+ });
146
+
147
+ // Handle files selected via file input
148
+ fileInput.addEventListener('change', () => {
149
+ handleFiles(fileInput.files);
150
+ });
151
+
152
+ function handleFiles(files) {
153
+ [...files].forEach(uploadFile);
154
+ }
155
+
156
+ function uploadFile(file) {
157
+ if (!file.type.startsWith('image/')) {
158
+ alert('Please upload only image files.');
159
+ return;
160
+ }
161
+
162
+ const reader = new FileReader();
163
+
164
+ reader.onload = function(e) {
165
+ const img = document.createElement('img');
166
+ img.src = e.target.result;
167
+ gallery.appendChild(img);
168
+ };
169
+
170
+ reader.readAsDataURL(file);
171
+ }
172
+ });
173
+ </script>
174
  </body>
175
  </html>