【发布时间】:2017-11-25 22:16:03
【问题描述】:
我正在尝试在我的网页上使用一些 CSS 和 JavaScript。
我有 3 个盒子,我希望所有 3 个盒子都更改为不同的颜色并渲染到屏幕上并再次更改颜色。
例如, 我在屏幕上有 3 个黑框。当我点击一个按钮 程序将等待 2 秒 然后 3 个框将变为红色。等待 2 秒 然后 3 个框将变为蓝色。等待 2 秒 然后这 3 个框将变为绿色。
这是我所拥有的:
elem1 = document.getElementById('1')
elem2 = document.getElementById('2')
elem3 = document.getElementById('3')
colorlist = ['purple', 'red', 'blue', 'green']
function changeColor() {
showRed()
//wait 2 seconds
showBlue()
//wait 2 seconds
showGreen()
//wait 2 seconds
}
function showRed() {
elem1.style.background = "red"
elem2.style.background = "blue"
elem3.style.background = "green"
}
function showBlue() {
elem1.style.background = "blue"
elem2.style.background = "green"
elem3.style.background = "red"
}
function showGreen() {
elem1.style.background = "green"
elem2.style.background = "red"
elem3.style.background = "blue"
}
* {
box-sizing: border-box;
}
.column3 {
float: left;
min-width: 15px;
max-width: 15px;
min-height: 15px;
max-height: 15px;
padding: 15px;
background-color: black;
border-style: solid;
border-width: medium;
border-color: white;
}
.row:after {
content: "";
display: table;
clear: both;
}
<div class="row">
<div class="column3" id="1"></div>
<div class="column3" id="2"></div>
<div class="column3" id='3'></div>
<button onclick='changeColor()'> Test </button>
</div>
【问题讨论】:
-
那你想要什么?为什么拒绝我的回答?随心所欲。
-
我没有对你的回答投反对票,其他人投了反对票。它不会显示我的投票,因为我的声望低于 15。
标签: javascript html css