我正在尝试使用CSS使我的对话框组件的::background伪元素。我已经能够在Edge和Chrome上实现它,但似乎Firefox没有正确应用过渡。
有谁知道FF不支持这一点,或者我的代码是错误的?模态本身尊重不透明度过渡,它只是立即出现的::background伪元素。
这是我用来快速验证概念的代码:
const dialog = document.querySelector('dialog')
const openBtn = document.querySelector('#openBtn')
const closeBtn = document.querySelector('#closeBtn')
openBtn.addEventListener('click', open)
closeBtn.addEventListener('click', close)
function open() {
dialog.showModal()
dialog.classList.add('active')
}
function close() {
dialog.close()
dialog.classList.remove('active')
}
dialog {
opacity: 0;
transition: opacity cubic-bezier(0.35, 0, 0.2, 1) 2s;
}
dialog.active {
opacity: 1;
}
dialog::backdrop {
background: black;
transition: opacity cubic-bezier(0.35, 0, 0.2, 1) 2s;
opacity: 0;
}
dialog.active::backdrop {
opacity: 0.8;
}
<dialog>
<p>test nice</p>
<button id="closeBtn">close dialog</button>
</dialog>
<button id="openBtn">
open dialog
</button>
1条答案
按热度按时间wnrlj8wa1#
是的,我检查了-似乎
transition
和animation
的::backdrop
都不能在firefox中工作。作为替代,我建议将
box-shadow
设置为dialog
:dialog
时有动画:*