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 |
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="https://unpkg.com/js-image-zoom@0.4.1/js-image-zoom.js" type="application/javascript"></script> </head> <body> <input type="file" id="imageInput" accept="image/*" /> <div id="img-container" style="width: 400px; margin-top: 20px;"> <!-- Image will be displayed here after selection --> </div> <script> // File input event listener document.getElementById("imageInput").addEventListener("change", function (event) { var imgContainer = document.getElementById("img-container"); imgContainer.innerHTML = ""; // Clear any previously displayed image var file = event.target.files[0]; if (file) { var reader = new FileReader(); reader.onload = function (e) { var img = document.createElement("img"); img.src = e.target.result; // Set the source to the selected file img.style.width = "100%"; // Set image width to 100% of the container imgContainer.appendChild(img); // Append the image to the container // Initialize ImageZoom with options var options = { width: 400, zoomWidth: 500, offset: { vertical: 0, horizontal: 10 } }; new ImageZoom(imgContainer, options); }; reader.readAsDataURL(file); // Read the selected file } }); </script> </body> </html> |