我有一个响应式图像网格,它运行良好,我很满意。
现在我想向图像添加悬停效果,以便应用白色半透明滤镜,并且文本出现在图像上,并在图像上显示更多详细信息。 我还希望图像在单击时成为模式并弹出。
似乎当我应用悬停效果时,弹出图像停止工作。 谁能告诉我出了什么问题吗? 注意:我知道悬停效果尚未应用于所有图像。这是因为当我意识到它不起作用时我并没有打扰。
var modalEle = document.querySelector(".modal");
var modalImage = document.querySelector(".modalImage");
Array.from(document.querySelectorAll(".ImgThumbnail")).forEach(item => {
item.addEventListener("click", event => {
modalEle.style.display = "block";
modalImage.src = event.target.src;
});
});
document.querySelector(".close").addEventListener("click", () => {
modalEle.style.display = "none";
});
<html>
<body>
<!--MAIN CONTENT-->
<main>
<div class="row">
<div class="column">
<div class="container">
<img class="ImgThumbnail" src="images/Painting/Oranges in Berlin.jpg" alt="">
<div class="overlay">
<div class="text">caption content</div>
</div>
</div>
<img class="ImgThumbnail" src="images/Painting/Bread Rolls.jpeg" alt="">
<img class="ImgThumbnail" src="images/Painting/the Market.jpg" alt="">
<img class="ImgThumbnail" src="images/Painting/Life Drawing with card.jpg" alt="">
<img class="ImgThumbnail" src="images/Painting/Copy of The Carrofs IV.jpg" alt="">
<img class="ImgThumbnail" src="images/Painting/The Carrofs I.JPG" alt="">
<img class="ImgThumbnail" src="images/Painting/The Trig, from memory.jpg" alt="">
<img class="ImgThumbnail" src="images/Painting/The Beacon.jpg" alt="">
<img class="ImgThumbnail" src="images/Painting/Farm on the Hill.jpg" alt="">
<img class="ImgThumbnail" src="images/Painting/Terrace Sunlight.jpg" alt="">
<img class="ImgThumbnail" src="images/Painting/Across the Road.jpg" alt="">
<img class="ImgThumbnail" src="images/Painting/Back Lane I.jpg" alt="">
</div>
<div class="modal">
<span class="close">×</span>
<img class="modalImage" id="img01">
</div>
</main>
</body>
</html>
收到一只叮咚
qq_笑_17
相关分类