2014-07-11 3 views
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> 

자바 스크립트 코드

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에서 사용해 보았습니다.)

+0

2 개 클래스 ... 한 숨 깁니다 ... 표시 1 - 1 :

다음은이 자바 스크립트 트릭을 할 것으로 보이는 link to a demo

입니다 꺼져. 참고 : 효과를 양방향으로 사용하려면 양쪽 모두에 전환을 배치하십시오. choise = choice :) – zgr024

+1

요소에서 스타일을 변경하는 대신 CSS 클래스 이름을 스왑하고 스타일 시트에서 작업을 수행하십시오. –

+0

HTML에 문제가 있습니다 ... –

답변

1

변환하려면 픽셀 값을 입력해야합니다. '0px'에서 'auto'로 전환 할 수 없습니다. ... 다음에 숨 깁니다 클래스를 전환

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 = "50px"; //"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 = "50px"; //"PartieBAS" appear 
    } 
    else 
    { 
     document.getElementById("PartieBAS").style.height = "0px"; //"PartieBAS" disappear 
     document.getElementById("PartieCPP").style.height = "0px"; //"PartieCPP" disappear 
    } 
} 
+0

고마워요, 잘 작동합니다! :) –

관련 문제