我只是簡單地改變當我點擊它時更改按鈕的color
和background-color
。爲什麼更改通過JavaScript的樣式會受到CSS轉換的影響
<input type="button" value="click me" id="myButton" onclick="ChangeColor()"/>
這個按鈕的CSS包含了color
和background-color
CSS過渡,但是,我並沒有添加任何樣式:hover
僞元素上,我並沒有改變顏色。
#myButton{
color:#3399FF;
background-color:#FFFFFF;
/* These transitions are supposed to change the color in case I hover over the button */
-webkit-transition: background 0.5s,color 0.5s;
-moz-transition: background 0.5s,color 0.5s;
transition: background 0.5s,color 0.5s;
}
#myButton:hover{
/* But since there's nothing here, the color won't change when I hover */
}
現在,當我通過JavaScript改變風格,他們改變而使用的過渡,意味着,它的顏色會0.5s
後更改,而不是瞬間。
function ChangeColor()
{
document.getElementById("myButton").style.color = "#FFFFFF";
document.getElementById("myButton").style.backgroundColor = "#3399FF";
}
這真是一件好事,我喜歡它,但我只是想知道,JavaScript如何尊重CSS3轉換?有沒有這方面的文件?
'CSS3' transitions本來就是我認爲的瀏覽器支持的。 – 2013-03-15 23:47:17