我正在YouTube上观看一个项目的视频,一个简单的石头剪刀布游戏。根据我已经完成的,我应该可以点击让我们玩按钮,介绍屏幕应该淡出,但它不工作。我猜可能是在js文件中有什么错误,但我不能确定问题所在。
const game = () => {
let pScore = 0;
let cScore = 0;
const startGame = () => {
const playBtn = document.querySelector('.intro button');
const introScreen = document.querySelector('.intro');
const match = document.querySelector('.match');
playBtn.addEventListener('click', () => {
introScreen.classList('.fadeOut');
});
};
};
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
section {
height: 100vh;
background-color: rgb(39, 41, 68);
font-family: sans-serif;
}
.score {
color: rgb(224, 224, 224);
height: 20vh;
display: flex;
justify-content: space-around;
align-items: center;
}
.score h2 {
font-size: 30px;
}
.score p {
text-align: center;
padding: 10px;
font-size: 25px;
}
.intro {
background-color: rgb(39, 41, 68);
height: 50vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
transition: opacity 0.5s ease;
}
.intro h1 {
font-size: 50px;
}
.intro button,
.match button {
width: 150px;
height: 50px;
font-size: 20px;
background: none;
border: none;
color: rgb(45, 117, 96);
border-radius: 3px;
background-color: rgb(45, 117, 96);
color: rgb(224, 225, 224);
cursor: pointer;
}
.match {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
transition: opacity 0.5s ease 0.5s;
}
.winner {
color: rgb(224, 224, 224);
text-align: center;
font-size: 50px;
}
.hands,
.options {
display: flex;
justify-content: space-around;
align-items: center;
}
.Player-hand {
transform: rotatey(180deg);
}
div.fadeOut {
opacity: 0;
pointer-events: none;
}
div.fadeIn {
opacity: 1;
pointer-events: all;
}
<section>
<div class="score">
<div class="player-score">
<h2>Player</h2>
<p>0</p>
</div>
<div class="computer-score">
<h2>Computer</h2>
<p>0</p>
</div>
</div>
<div class="intro">
<h1>Rock paper scissors</h1>
<button>Let's Play</button>
</div>
<div class="match fadeOut">
<h2 class="winner">Choose an option</h2>
<div class="hands">
<img class="Player-hand" src="./assets/rock.png" alt="">
<img class="computer-hand" src="./assets/rock.png" alt="">
</div>
<div class="options">
<button>rock</button>
<Button>paper</button>
<button>scissors</button>
</div>
</div>
</section>
1条答案
按热度按时间tkclm6bt1#
没有类似
classList()
的方法您应该:
来源:Element.classList
顺便说一句,你不会在任何地方调用这些函数,我希望它像这样: