【发布时间】:2021-11-02 15:45:04
【问题描述】:
我有这个.endGame div,我想隐藏它,然后在需要时再次显示。所以我创建了.endGameDisplay 来隐藏它,但它不起作用,我不知道为什么。
仅当display: none; 在.endGame 中时才会隐藏
在 java 脚本中,我希望它在页面打开时隐藏,所以我有这样的东西:
const endGame = document.querySelector('.endGame');
endGameOff();
//end game on func
function endGameOn() {
endGame.classList.remove('.endGameDisplay');
}
//end game off func
function endGameOff() {
endGame.classList.add('.endGameDisplay');
}
我还尝试将classlist.add 更改为.remove 以检查我是否没有记错但仍然没有。
我的 HTML:
<div class="endGame">
<h1>You</h1>
<h2 class="wonORlost">text</h2>
<h3>Do you want to restar game or go back to the menu?</h3>
<div class="btns">
<div class="restart">Restart</div>
<div class="exit">Exit</div>
</div>
</div>
我的 CSS:
.endGame {
position: absolute;
z-index: 1;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
background: $primary-color;
color: $white-color;
border-radius: 25px;
text-align: center;
box-shadow: 0 0 15px #333;
.h1 {
font-weight: $font-bold;
}
.h2 {
font-weight: $font-bold;
color: lighten($bot-color, 15%);
}
.h3 {
font-weight: $font-normal;
}
.btns {
display: grid;
justify-content: center;
justify-items: center;
.restart {
background: $green-color;
cursor: pointer;
@include transition-ease;
&:hover {
background: darken($green-color, 10%);
@include transition-ease;
}
}
.exit {
background: $red-color;
cursor: pointer;
@include transition-ease;
&:hover {
background: darken($red-color, 10%);
@include transition-ease;
}
}
}
&.endGameDisplay {
display: none;
}
}
【问题讨论】:
标签: javascript html css hide absolute