加载页面时,我使用了一个模式来创建一个弹出框。
我的代码在我的测试代码笔上运行得非常好:
https://codepen.io/nico3d911/pen/yjBRrK?editors=1010
但当我想把它放在我真正的项目中,基本上是复制粘贴,我没有任何结果:(
https://codepen.io/nico3d911/pen/odvmPR?editors=1011
HTML:
<div class="modal">
<div class="modal-content">
<h1>Choose your team!</h1>
<span class="close-button" style='color:#4286f4' onclick = 'test()'>X</span>
<span class="close-button" style='color:#e29126' onclick = 'test()'>O</span>
</div>
</div>
CSS:
.modal {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
opacity: 0;
visibility: hidden;
transform: scale(1.1);
transition: visibility 0s linear 0.25s, opacity 0.25s 0s, transform 0.25s;
}
.modal-content {
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: white;
padding: 1rem 1.5rem;
width: 24rem;
border-radius: 0.5rem;
}
.close-button {
display: inline-block;
margin: 0 auto;
width: 1.5rem;
line-height: 1.5rem;
cursor: pointer;
border-radius: 100%;
border: 2px solid lightgray;
padding: 20px;
margin: 10px 15px 10px 15px;
font-size:2em;
}
.close-button:hover {
border: 2px solid #3fcc64;
}
.show-modal {
opacity: 1;
visibility: visible;
transform: scale(1.0);
transition: visibility 0s linear 0s, opacity 0.25s 0s, transform 0.25s;
}
Javascript:
// Modal
window.onload = function(){
toggleModal();
};
var modal = document.querySelector(".modal");
function toggleModal() {
modal.classList.toggle("show-modal");
}
function test() {
modal.classList.toggle("show-modal");
player.team = 'X';
console.log(player);
}
我在页面上也有一个覆盖图,但我不认为这两个有冲突。。。
谢谢你的帮助!