Onise commited on
Commit
cee54ce
·
verified ·
1 Parent(s): d8b5ea1

add upload from computer image then display it

Browse files
Files changed (3) hide show
  1. index.html +14 -3
  2. script.js +19 -1
  3. style.css +15 -1
index.html CHANGED
@@ -58,14 +58,25 @@
58
  <p class="text-gray-600 dark:text-gray-300">Built with dark mode support out of the box.</p>
59
  </div>
60
  </div>
61
-
62
- <div class="mt-16 text-center">
63
  <button id="themeToggle" class="px-6 py-3 bg-primary-500 hover:bg-primary-600 text-white rounded-lg font-medium transition-colors flex items-center mx-auto">
64
  <i data-feather="moon" class="mr-2"></i>
65
  Toggle Theme
66
  </button>
 
 
 
 
 
 
 
 
 
 
 
 
67
  </div>
68
- </main>
69
 
70
  <custom-footer></custom-footer>
71
 
 
58
  <p class="text-gray-600 dark:text-gray-300">Built with dark mode support out of the box.</p>
59
  </div>
60
  </div>
61
+ <div class="mt-16 text-center space-y-8">
 
62
  <button id="themeToggle" class="px-6 py-3 bg-primary-500 hover:bg-primary-600 text-white rounded-lg font-medium transition-colors flex items-center mx-auto">
63
  <i data-feather="moon" class="mr-2"></i>
64
  Toggle Theme
65
  </button>
66
+
67
+ <div class="bg-white dark:bg-gray-800 p-6 rounded-xl shadow-lg max-w-md mx-auto">
68
+ <h2 class="text-xl font-semibold mb-4 text-gray-800 dark:text-white">Upload Image</h2>
69
+ <input type="file" id="imageUpload" accept="image/*" class="hidden">
70
+ <label for="imageUpload" class="cursor-pointer px-4 py-2 bg-secondary-500 hover:bg-secondary-600 text-white rounded-lg inline-flex items-center">
71
+ <i data-feather="upload" class="mr-2"></i>
72
+ Choose Image
73
+ </label>
74
+ <div id="imagePreview" class="mt-4 hidden">
75
+ <img id="previewImage" class="max-w-full h-auto rounded-lg" src="#" alt="Preview">
76
+ </div>
77
+ </div>
78
  </div>
79
+ </main>
80
 
81
  <custom-footer></custom-footer>
82
 
script.js CHANGED
@@ -30,7 +30,6 @@ document.addEventListener('DOMContentLoaded', () => {
30
  }
31
  feather.replace();
32
  });
33
-
34
  // Watch for system theme changes
35
  prefersDarkScheme.addEventListener('change', e => {
36
  if (localStorage.getItem('theme') === null) {
@@ -41,4 +40,23 @@ document.addEventListener('DOMContentLoaded', () => {
41
  }
42
  }
43
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  });
 
30
  }
31
  feather.replace();
32
  });
 
33
  // Watch for system theme changes
34
  prefersDarkScheme.addEventListener('change', e => {
35
  if (localStorage.getItem('theme') === null) {
 
40
  }
41
  }
42
  });
43
+
44
+ // Image upload and preview functionality
45
+ const imageUpload = document.getElementById('imageUpload');
46
+ const imagePreview = document.getElementById('imagePreview');
47
+ const previewImage = document.getElementById('previewImage');
48
+
49
+ imageUpload.addEventListener('change', function(e) {
50
+ const file = e.target.files[0];
51
+ if (file) {
52
+ const reader = new FileReader();
53
+
54
+ reader.onload = function(event) {
55
+ previewImage.src = event.target.result;
56
+ imagePreview.classList.remove('hidden');
57
+ }
58
+
59
+ reader.readAsDataURL(file);
60
+ }
61
+ });
62
  });
style.css CHANGED
@@ -17,11 +17,25 @@ body {
17
  ::-webkit-scrollbar-track {
18
  background: #f1f1f1;
19
  }
20
-
21
  .dark ::-webkit-scrollbar-track {
22
  background: #1a1a1a;
23
  }
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  ::-webkit-scrollbar-thumb {
26
  background: #888;
27
  border-radius: 4px;
 
17
  ::-webkit-scrollbar-track {
18
  background: #f1f1f1;
19
  }
 
20
  .dark ::-webkit-scrollbar-track {
21
  background: #1a1a1a;
22
  }
23
 
24
+ /* Image preview styling */
25
+ #imagePreview {
26
+ transition: all 0.3s ease;
27
+ }
28
+
29
+ #previewImage {
30
+ max-height: 300px;
31
+ object-fit: contain;
32
+ border: 1px solid #e5e7eb;
33
+ box-shadow: 0 1px 3px rgba(0,0,0,0.1);
34
+ }
35
+
36
+ .dark #previewImage {
37
+ border-color: #374151;
38
+ }
39
  ::-webkit-scrollbar-thumb {
40
  background: #888;
41
  border-radius: 4px;