我是 web 开发的新手,想知道是否有一种方法可以在不使用 css 高度转换的情况下使 div 垂直打开。我还必须将不透明度过渡添加到带有文本的 div,因为它在主 div 出现之前显示。这是一个演示http://jsfiddle.net/wq7v7/
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script>
window.onload = function(){
document.getElementById("body").setAttribute("class","loaded");
}
</script>
<style type="text/css">
.fadein {
height: 0px;
transition: height 0.7s;
-moz-transition: height 0.7s;
-webkit-transition: height 0.7s;
-o-transition: height 0.7s;
background-color: #39F;
width: 600px;
border-top-width: 2px;
border-bottom-width: 2px;
border-top-style: solid;
border-bottom-style: solid;
border-top-color: #000;
border-bottom-color: #000;
}
#body.loaded .fadein {
height: 200px;
opacity: 1;
}
.thebox {
opacity: 0;
transition: opacity 0.5s;
-moz-transition: opacity 0.5s;
-webkit-transition: opacity 0.5s;
-o-transition: opacity 0.5s;
}
#body.loaded .thebox {
opacity: 1;
}
</style>
</head>
<body id="body">
<div class="fadein">
<div class="thebox" style="text-align:center; color:#000; font-size:24px; font-family:'Myriad Pro'; margin-top:10px;">
Choose your city
</div>
</div>
</body>
</html>