screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> </head> <body> <div id="app"> <h3>Vue Js Multiple Image Upload with Preview</h3> <label for="file-upload">Choose Image</label> <input type="file" id="file-upload" multiple @change="handleFileUpload"> <div class="image-container"> <div v-for="(image, index) in images" :key="index" class="image-item"> <img :src="image.previewUrl" alt="Preview" class="profile-pic" @click="showImage(index)"> <button class="remove-button" @click="removeImage(index)">X</button> </div> </div> <div v-if="showModal" class="modal" @click.self=" closeModal"> <div class="modal-content"> <span class="close" @click="closeModal">×</span> <img :src="selectedImage.previewUrl" alt="Preview" class="modal-image"> </div> </div> </div> <script type="module"> const app = Vue.createApp({ data() { return { images: [], showModal: false, selectedImage: null }; }, methods: { handleFileUpload(event) { const files = event.target.files; for (let i = 0; i < files.length; i++) { const reader = new FileReader(); reader.onload = (e) => { this.images.push({ file: files[i], previewUrl: e.target.result }); }; reader.readAsDataURL(files[i]); } }, removeImage(index) { this.images.splice(index, 1); }, showImage(index) { this.selectedImage = this.images[index]; this.showModal = true; }, closeModal() { this.showModal = false; this.selectedImage = null; } } }); app.mount('#app'); </script> <style> /* Center the content vertically and horizontally */ #app { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; font-family: Arial, sans-serif; } /* Style for the file input */ input[type="file"] { display: none; } /* Style for the file input label */ label { padding: 10px 20px; background-color: #4285f4; color: #ffffff; font-size: 16px; font-weight: bold; cursor: pointer; border-radius: 4px; transition: background-color 0.3s ease; } label:hover { background-color: #3367d6; } .image-container { display: flex; flex-wrap: wrap; margin-top: 20px; } .image-item { position: relative; margin-right: 10px; margin-bottom: 10px; } .profile-pic { width: 80px; height: 80px; object-fit: cover; border-radius: 50%; cursor: pointer; } .remove-button { position: absolute; top: 5px; right: 5px; padding: 5px; background-color: #f44336; color: white; border: none; border-radius: 50%; cursor: pointer; font-weight: bold; } .remove-button:hover { background-color: #d32f2f; } /* Modal styles */ .modal { display: block; position: fixed; z-index: 1; padding-top: 50px; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0, 0, 0, 0.8); } .modal-content { margin: auto; display: flex; justify-content: center; align-items: center; width: 80%; max-width: 800px; height: 80%; } .modal-image { width: 100%; height: auto; object-fit: contain; } .close { position: absolute; top: 20px; right: 30px; font-size: 35px; font-weight: bold; color: #f1f1f1; cursor: pointer; } .close:hover, .close:focus { color: #bbb; text-decoration: none; cursor: pointer; } </style> </body> </html>