Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate an object and scale it from the top

I'm trying to create a div that appears on hover by rotating in X position from top to bottom, I also want to add some realistic to it's rotation(The width of the DIV from the bottom should always be 100%, but should increase gradually from 20% to 100% white it's rotating).

enter image description here

.img-event-parent{
	position: relative;
}
.img-event-details{
	position: absolute;
	background-color: rgba(0,0,0,0.8);
	left: 0px;
	right: 0px;
	top: 0px;
	height: 100%;
	transform: rotateX(90deg);
	transform-style: preserve-3d;
    -webkit-transform: rotateX(90deg);
	transform-origin: bottom;
    transition: all 3s;
}
.img-event-parent:hover .img-event-details{
	transform: rotateX(0deg);	
}
<div class="img-event">
    <div class="img-event-parent img-parent">
      <a href="#">
      <img src="https://images.pexels.com/photos/20787/pexels-photo.jpg?auto=compress&cs=tinysrgb&h=350" alt="">
    </a>
    <div class="img-event-details">
      <a href="#" class="slick-desc"><?=$key->post_title?></a>
    </div>
  </div>
</div>

The snippet above rotates the img-event-details div, but I don't know how can I resize the div width from the top only(As shown in the image above) while rotating.

like image 316
Yazan W Yusuf Avatar asked Jun 20 '18 09:06

Yazan W Yusuf


1 Answers

Add some perspective:

.img-event-parent {
  position: relative;
  display: inline-block;
  perspective: 200px; /*Added this*/
  perspective-origin: bottom; /*Added this*/
}

.img-event-parent img {
  display: block;
}

.img-event-details {
  position: absolute;
  background-color: rgba(0, 0, 0, 0.8);
  left: 0px;
  right: 0px;
  top: 0px;
  height: 100%;
  transform: rotateX(90deg);
  transform-style: preserve-3d;
  transform-origin: bottom;
  transition: all 3s;
}

.img-event-parent:hover .img-event-details {
  transform: rotateX(0deg);
}
<div class="img-event">
  <div class="img-event-parent img-parent">
    <a href="#">
      <img src="https://images.pexels.com/photos/20787/pexels-photo.jpg?auto=compress&cs=tinysrgb&h=300" alt="">
    </a>
    <div class="img-event-details">
      <a href="#" class="slick-desc">Some text</a>
    </div>
  </div>
</div>
like image 109
Temani Afif Avatar answered Nov 08 '22 09:11

Temani Afif