If you use jQuery
it's simple. And in future don't use some animation on body
. Use it to inner div. Here is the fiddle
Div opens vertically when page loaded with javascript and css
-
28-06-2022 - |
Question
Im new to web developing and would like to know if there is a way to make the div open vertically without the use of css height transitions. I also to had to add the opacity transition to the div with text since its showing before the main div appears. Here is a demo 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>
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow