问题描述
我有一个 javascript 灯箱,我想要淡入淡出过渡。我想通过不透明度 0.5s 和线性来拥有它。任何人都知道如何在 javascript 中做到这一点?
const lightbox = document.createElement('div')
lightbox.id = 'lightbox'
document.body.appendChild(lightbox)
const images = document.querySelectorAll('img')
images.forEach(image => {
image.addEventListener('click',e => {
lightbox.classList.add('active')
const img = document.createElement('img')
img.src = image.src
while (lightbox.firstChild) {
lightbox.removeChild(lightbox.firstChild)
}
lightbox.appendChild(img)
})
})
lightbox.addEventListener('click',e => {
if (e.target !== e.currentTarget) return
lightbox.classList.remove('active')
})
img{
cursor: pointer;
}
#lightbox{
z-index: 99;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(28,33,37,0.8);
display: none;
backdrop-filter: blur(1px);
}
#lightbox img{
height: 80%;
}
#lightbox.active{
display: flex;
justify-content: center;
align-items: center;
position: fixed;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)