我正在模態(tài)窗口中創(chuàng)建幻燈片放映!首先,我單擊網(wǎng)站上的12張圖像中的一張...然后打開模態(tài)窗口,其中包含帶有幻燈片放映的窗口...應將我單擊的圖片(img)視為背景圖片(作為背景圖片)幻燈片中的第一張圖片。網(wǎng)頁上的圖片位于id為pic_cnt的div中在模態(tài)幻燈片顯示窗口的div(id modal_window)中,有12個div(每個圖片),其類別為modal_pic!具有此類的每個div的背景圖像的順序與網(wǎng)頁上的img順序相同,但不透明度為0。我在頁面上的每個img上添加了一個事件監(jiān)聽器,以打開模式窗口!如何將單擊的img與相同的背景圖像連接起來?單擊img后,應添加模態(tài)窗口中具有相同背景圖像的類(.current),以將不透明度更改為1。請幫助!let modal = document.getElementById('modal');let clickedPic = document.querySelectorAll('#pic_cnt img');let modalPic = document.querySelectorAll('#modal_window div');for (let i = 0; i < clickedPic.length; i++) { clickedPic[i].addEventListener('click', openModal)}function openModal() { modal.style.display = "block";}#modal { display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; z-index: 2; background-color: rgba(1, 1, 1, .8);}#modal_window { background-color: white; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); height: 55%; width: 55%;}.modal_pic { width: 100%; height: 100%; ; position: absolute; opacity: 0;}.current { opacity: 1;}
如何準確識別觸發(fā)事件偵聽器的元素?
qq_笑_17
2021-05-06 14:23:23