1 回答
TA贡献2051条经验 获得超10个赞
let moviePics = function() {
document.querySelectorAll('.avengerPic').forEach(function(e) {
const randomPic = Math.floor((Math.random() * picArray.length));
e.src = picArray[randomPic].thumbnail;
});
}
moviePics();
let imgs= document.querySelectorAll(".avengerPic");
let closeBtns = document.querySelectorAll(".close");
for (var i=0; i<imgs.length; i++){
imgs[i].addEventListener('click', function(){
let thumbSrc = this.src;
let bigImgSrc;
for(var j=0; j<picArray.length; j++){
if (thumbSrc == picArray[j].thumbnail){
bigImgSrc = picArray[j].image
}
}
this.nextElementSibling.style.display = "block";
this.nextElementSibling.children[1].src = bigImgSrc;
this.nextElementSibling.children[2].innerHTML = this.alt;
})
}
for (var i=0; i<closeBtns.length; i++){
closeBtns[i].addEventListener('click', function(){
this.parentElement.style.display = "none";
})
}
添加回答
举报