我目前正在用HTML,CSS和jQuery製作遊戲。這將是通常的下降塊避免遊戲。爲什麼我的div不能正常顯示?
雖然我有麻煩,但我的jQuery。當我選擇一個主題(僅適用於黑暗的主題目前正在 「工作」),玩家不露面:
$(document).ready(function() {
$('#options').change(function() { // NOTE: all themes have capital letters on colors
if ($(this).val() === 'Dark') {
$("#game").css("background-color", "black");
$("#player").css({
"background-color": "white" // using CSS function in case you want to add other stuff
});
}
});
$("#play").click(function() {
$(this).hide();
$("#options").hide();
$("#player").show();
});
});
body {
background-color: #FFFFFF;
font-family: helvetica, sans-serif;
}
.block {
width: 60px;
height: 60px;
position: absolute
}
#game {
width: 1000px;
height: 550px;
border: 3px solid #000000;
margin: 2% 10%;
}
#player {
width: 40px;
height: 40px;
left: 50%;
bottom: 0;
position: absolute
}
#play {
padding: 1%;
color: white;
background-color: black;
border-style: solid;
}
#options {}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Trash Fall - Game</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<!-- adding jQuery to the script -->
<script src="script.js"></script>
</head>
<body>
<h1 id="main_title">Color Drop</h1>
<div id="game">
<button id="play">Play</button>
<select id="options">
<option value="none">none (choose one in order to play)</option>
<option value="Dark">Dark</option>
<option value="Light">Light</option>
<option value="Blue_White">Blue/White</option>
<option value="Red_White">Red/White</option>
</select>
<div id="player"></div>
</div>
</body>
</html>
注意:我看到這是在這個片段中工作,但它不工作在github上(我在創建t他的遊戲):example GitHub
爲什麼這不起作用?
另外:爲什麼主題和玩家被添加到遊戲部分,因爲我們選擇主題?
GitHub的鏈接:https://github.com/FlipFloop/Color-Drop
感謝所有!
究竟是不是工作?當我選擇黑暗主題時,我在黑色背景上看到一個白色框。我正在運行Chrome。 –
@Fabio看看GitHub示例 – FlipFloop
我正在看它。它應該做什麼?代碼片段和github示例都給出了相同的結果 –