write on file html\css\js modern code for smart grid\tiles with small and big images and…
- User
write on file html\css\js modern code for smart grid\tiles with small and big images and tiny gap, also make modal for full view. example url https://ik.imagekit.io/ll20/tr:w-800,h-400/R/VIP2000/0001.JPG (all file names range: 0001-0086).
- Assistant
Creating a smart grid layout with tiles that can accommodate small and big images, along with a tiny gap between them, and a modal for full view requires HTML, CSS, and JavaScript. Below is a modern code example that achieves this. This example assumes you have a series of images with filenames ranging from
0001.JPGto0086.JPGlocated at a specific URL.HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Smart Grid Tiles</title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="grid-container"></div> <!-- Modal for full view --> <div class="modal" id="imageModal"> <img class="modal-content" id="modalImage"> <span class="close">×</span> </div> <script src="script.js"></script> </body> </html>CSS (
style.css)body, html { margin: 0; padding: 0; width: 100%; height: 100%; overflow-x: hidden; } .grid-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 5px; padding: 10px; } .grid-item img { width: 100%; height: 150px; object-fit: cover; cursor: pointer; } .modal { display: none; /* Hidden by default */ position: fixed; /* Stay in place */ z-index: 1; /* Sit on top */ left: 0; top: 0; width: 100%; /* Full width */ height: 100%; /* Full height */ overflow: auto; /* Enable scroll if needed */ background-color: rgb(0,0,0); /* Fallback color */ background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ } .modal-content { margin: auto; display: block; width: 80%; max-width: 700px; } .close { color: #aaa; float: right; font-size: 28px; font-weight: bold; } .close:hover, .close:focus { color: black; text-decoration: none; cursor: pointer; }JavaScript (
script.js)document.addEventListener('DOMContentLoaded', function() { const gridContainer = document.querySelector('.grid-container'); const modal = document.getElementById("imageModal"); const modalImage = document.getElementById("modalImage"); const closeBtn = document.querySelector(".close"); // Function to create grid items function createGridItems() { for (let i = 1; i <= 86; i++) { const img = document.createElement('img'); img.src = `https://ik.imagekit.io/ll20/tr:w-800,h-400/R/VIP2000/000${i.toString().padStart(4, '0')}.JPG`; img.alt = `Image ${i}`; img.addEventListener('click', function() { modal.style.display = "block"; modalImage.src = this.src; }); const gridItem = document.createElement('div'); gridItem.classList.add('grid-item'); gridItem.appendChild(img); gridContainer.appendChild(gridItem); } } // Close modal closeBtn.onclick = function() { modal.style.display = "none"; } // Close modal when clicking outside window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; } } createGridItems(); });This code creates a grid of images with a tiny gap between them. When an image is clicked, a modal opens displaying the image in a larger format. The modal can be closed by clicking on the close button or by clicking outside the image.
Please ensure that your server or hosting environment allows cross-origin resource sharing (CORS) for the images if they are hosted on a different domain than your webpage, as shown in the example URL. Some servers might block requests from scripts running in browsers for security reasons.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.