我正在尝试使用vanilla JS切换模式,但是显示按钮不起作用。我希望模式在单击显示按钮时添加一个类 - 位于项目框的右下角。显示类将模态显示为 100vhx100vw 框。
这是我的代码:
// Variables
let buttonOne = document.getElementById("project-1-button");
let modalOne = document.getElementById("project-1-modal");
let closeOne = document.getElementById("project-1-close");
// Functions
function modalOneShow() {
modalOne.classList.add("show");
}
function modalOneRemove() {
modalOne.classList.remove("show");
}
// Event Listeners
buttonOne.addEventListener("onclick", modalOneShow);
closeOne.addEventListener("onclick", modalOneRemove);
.projects-section {
height: auto;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.projects-container {
height: 90%;
width: 90%;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
margin: 100px 0;
}
.projects-heading {
height: auto;
width: 90%;
display: flex;
align-items: center;
justify-content: center;
margin: 30px 0;
}
.project-box {
height: 400px;
width: 800px;
display: flex;
align-items: center;
justify-content: center;
position: relative;
background-color: yellow;
}
.project-button {
height: 10%;
width: 40%;
display: flex;
align-items: center;
justify-content: flex-end;
position: absolute;
bottom: 5px;
right: 20px;
}
.project-button h4 {
border-bottom: 1px solid #000;
cursor: pointer;
}
.project-modal {
height: 100vh;
width: 100%;
align-items: center;
justify-content: center;
z-index: 10;
background-color: #e8ead3;
position: fixed;
top: 0;
left: 0;
}
.project-modal-content {
height: 90%;
width: 90%;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
position: relative;
}
.project-close {
height: 40px;
width: 40px;
position: absolute;
top: 0;
right: 10px;
cursor: pointer;
}
#project-1-modal {
display: none;
}
如果有人能为我指出我做错了什么的正确方向,那就太好了。谢谢!
三国纷争
慕森王
撒科打诨
相关分类