0

Please see this fiddle:

div {
  width:300px;
}
.upper {
  height:50px;
  background-color: red;
}
.middle {
  height: 100px;
  background-color: green;
}

.bottom {
  height: 900px;
  background-color: purple;
}
<div class="upper">

</div>
<div class="middle">

</div>
<div class="bottom">

</div>

I need a way to make an entrance for the green element: At first, it doesn't appear, then it appears and grows in-place and it pushes down the red element.

The only solution I found is to animate max-height property from 0px to other value. However, this solution is not the best because it causes layout thrashing

So I need to figure out how is it possible to do this with transform somehow.

another information - the height of the green element is not known, so the solution preferably not hard code its height.

LiranC
  • 2,400
  • 1
  • 27
  • 55

2 Answers2

0

A possible solution could be using transform: scale

transform: scale(height, width);
Crashtor
  • 1,249
  • 1
  • 13
  • 21
0

I think this is what you were looking for, a sliding effect

<!DOCTYPE html>
<html>
<head>
 <title></title>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>

<style type="text/css">
 div.same{
  width: 400px;
  height: 50px;
  margin: 30px;
  border: 5px solid yellow;
  display: none;
 }

 div#div1{
  background-color: orange;
 }
 div#div2{
  background-color: pink;
 }

 div#div3{
  background-color: purple;
 }
 div#div4{
  background-color: green;
 }
 div#div5{
  background-color: red;
 }
 div#div6{
  background-color: blue;
 }


</style>

<body>
 
<div class="same" id="div1"></div>
<div class="same" id="div2"></div>
<div class="same" id="div3"></div>
<div class="same" id="div4"></div>
<div class="same" id="div5"></div>
<div class="same" id="div6"></div>


 
</body>

<script type="text/javascript">
 
 $(document).ready(function(){
  for(var i=0;i<6;i++)
  {
   var theid = $("#div"+i);
   var thetime = 800 *i;
   $(theid).show(thetime); // or use .fadeIn()
   thetime = thetime * i;
  }
 });



</script>
</html>
Awais
  • 4,752
  • 4
  • 17
  • 40