所以我想創建一個Menorah,點擊按鈕點燃蠟燭,讓蠟燭變得更短,比方說每秒5px(肯定可以改變這個值)。我被卡在動畫上。我知道我需要訪問div的屬性,例如高度,並且還可以移動蠟燭的燈光,但我實際上不知道如何才能做到這一點。動態更改div的屬性
這裏是我到目前爲止的代碼:
var lightOn = document.createElement("BUTTON");
lightOn.textContent = "Light Menorah!";
document.body.appendChild(lightOn);
lightOn.onclick = setInterval (candleLight,1000);
function candleLight() {
document.getElementsByClassName("candles").innerHTML = style.height-10;
}
.candles {
background-color: blue;
width: 35px;
height: 90px;
margin-right: 10px;
float: left;
}
.mainCandle {
background-color: blue;
width: 35px;
height: 120px;
margin-right: 10px;
float: left;
}
.light {
background-color: yellow;
width: 35px;
height: 40px;
float: left;
margin-right: 10px;
}
#theLight {
}
#theCandle {
display:block;
position: relative;
padding-top: 40px;
}
<div id = "theLight">
<div class = "light"></div>
<div class = "light"></div>
<div class = "light"></div>
<div class = "light"></div>
<div class = "light"></div>
<div class = "light"></div>
<div class = "light"></div>
<div class = "light"></div>
<div class = "light"></div>
</div>
<div id = "theCandle">
<div class = "candles"></div>
<div class = "candles"></div>
<div class = "candles"></div>
<div class = "candles"></div>
<div class = "mainCandle"></div>
<div class = "candles"></div>
<div class = "candles"></div>
<div class = "candles"></div>
<div class = "candles"></div>
</div>
愛麗絲,你可以創建一個JSFiddle嗎?快樂的Chanoukkah和聖誕節給大家! –