旋转对象并从顶部缩放

时间:2018-06-20 09:06:57

标签: css css3 rotation css-transitions css-transforms

我正在尝试通过从上到下在X位置旋转来创建在悬停时显示的div,我也想为其旋转添加一些逼真感(DIV从底部开始的宽度应始终为100%,但应从20%逐渐增加到旋转的100%)。

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>

上面的代码片段旋转了img-event-details div,但是我不知道如何在旋转时仅从顶部调整div的宽度(如上图所示)。

1 个答案:

答案 0 :(得分:4)

添加一些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>