0
我的轉換不起作用,我不知道爲什麼。CSS3轉換不起作用
HTML代碼
<!-- The user can select here the language -->
<select name="language" id="language" onChange="ChangeLanguage()">
<option value=" " selected/>
<option value="Basic"/>Basic
<option value="C/C++" />C/C++
</select>
<div id="PartieCPP"> <!-- This <div> disappear when the user choose "Basic" -->
...
</div>
<div id="PartieBAS"> <!-- This <div> disappear when the user choose "C/C++" -->
...
</div>
JavaScript代碼
function ChangeLanguage() //this function is called when the user change the selected language
{
var choise = document.getElementById("language").options[document.getElementById("language").selectedIndex].value;
if (choise == "C/C++")
{
document.getElementById("PartieCPP").style.height = "auto"; //"PartieCPP" appear
document.getElementById("PartieBAS").style.height = "0px"; //"PartieBAS" disappear
}
else if (choise == "Basic")
{
document.getElementById("PartieCPP").style.height = "0px"; //"PartieCPP" disappear
document.getElementById("PartieBAS").style.height = "auto"; //"PartieBAS" appear
}
else
{
document.getElementById("PartieBAS").style.height = "0px"; //"PartieBAS" disappear
document.getElementById("PartieCPP").style.height = "0px"; //"PartieCPP" disappear
}
}
CSS代碼
#PartieCPP, #PartieBAS
{
height : 0px;
overflow : hidden;
-webkit-transition: height 2s;
-moz-transition: height 2s;
transition: height 2s;
}
此代碼工作正常,但沒有過渡,可有人向我解釋我在做什麼錯誤?
(我在Chrome和Firefox上試過)
使2班...... 1,隱藏... 1,顯示...然後切換隱藏的類並關閉。注意:如果您想要兩種效果,請將轉換置於兩者中。 choise = choice :) – zgr024
而不是改變元素上的樣式,只需交換CSS類名稱並讓樣式表完成工作即可。 –
您的HTML有問題... –