1 回答

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊
您必須在開始時(shí)使用“display:none”類創(chuàng)建“pop-up”div,然后使用JS刪除該“display:none”類并將內(nèi)部img src更改為您的img。這是工作代碼:https://jsfiddle.net/bcdu3L2j/1/
const imgs = document.getElementsByTagName('img');
const imgsArray = Array.from(imgs);
const popUp = document.getElementById('pop-up');
const popImg = document.querySelector('#pop-up img');
function popUpImage(e) {
const imgSrc = e.target.src;
popImg.src = imgSrc;
popUp.classList.remove("hidden");
}
imgsArray.forEach((img) => {
img.addEventListener('click', popUpImage);
})
popUp.addEventListener('click', () => {
popUp.classList.add("hidden");
});
- 1 回答
- 0 關(guān)注
- 109 瀏覽
添加回答
舉報(bào)