将div折叠出来以显示内容

时间:2016-06-18 19:25:14

标签: html css animation

我正在努力实现same effect here所以当你将鼠标悬停在div上时,它会折叠并显示内容,但我无法弄清楚如何执行此操作。

到目前为止,我可以使用以下代码将内容滑入。下面的代码和jsfiddle can be seen here

HTML

<div class="artist artist-1"></div>
<div id="artist-text">Hi there</div>

CSS

.artist-1:hover + #artist-text {
  display: block;
}

#artist-text {
  display: none;
  background-color: #000000;
  width: 130px;
  padding: 10px;
  position: absolute;
  left: 50%;
  top: 60%;
  animation-duration: 1s;
  animation-name: slideLeft;
}

.artist {
  height: 100px;
  width: 100px;
}

.artist-1 {
  background-color: red;
  position: absolute;
  left: 20%;
  top: 40%;
}

@keyframes slideLeft {
  from {
    margin-left: 100%;
    width: 100%; 
  }

  to {
    margin-left: 0%;
    width: 100%;
  }
}

2 个答案:

答案 0 :(得分:1)

I'm going to try and guide you in the right direction. They're using 3D transforms to create the flip card effect, alongside the transform-origin property. Here's a link to a tutorial showing an effect on which you can base your code:

https://desandro.github.io/3dtransforms/docs/card-flip.html

Also, here's a live example. It's probably not exactly what you need, but it will help you.

.card, .card-flip {
  position:absolute;
  display:block;
  background:lightgreen;
  width:200px;
  height:300px;
}

.card {
  z-index:1;
}

.container {
  perspective: 800px;
}

.card-flip {
  background:lightblue;
  margin-left:200px;
  transition: transform 1s;
  transform-origin:left;
  transform:rotateY(120deg);
  z-index:0;
}

.container:hover .card-flip {
  transform:rotateY(0deg);
}
<div class="container">
  <div class="card"></div>
  <div class="card-flip"></div>
</div>

答案 1 :(得分:0)

动画处于:悬停,它被称为翻转卡效果。

你可以通过改变变换来改变效果。过渡价值观。

Cubic bezier如果您想知道在哪里获取cubic-bezier函数的值。

.outer-wrapper {
  position: absolute;
  left: 0;
  top: 0;
}
.outer-wrapper:nth-child(2) {
  left: 600px;
}
.outer-wrapper:nth-child(3) {
  top: 300px;
}
.wrapper {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 0 0 20px;
}
.background-out,
.background-over {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
}
.background-info {
  position: absolute;
  left: 200px;
  top: 0;
  width: 100%;
  height: 100%; 
  visibility: hidden;
  opacity: 0.2;
  transform-origin: 0% 50% 0px;
  transform: rotateY(-90deg);
  background-color: grey;
}
.background-info .text {
  padding: 5px;
}
.background-out {
  background-color: red;
}
.background-over {
  background-color: green;
  visibility: hidden;
  opacity: 0;
  transform-origin: 100% 50% 0px;
  transform: rotateY(-90deg);
}
.wrapper:hover .background-out {
  visibility: hidden;
}
.wrapper:hover .background-over,
.wrapper:hover .background-info {
  transform: translate3d(0px,0px,0px) rotateY(0deg);
  transition: opacity 600ms cubic-bezier(0.55, 0.31, 0.15, 0.93) 0ms,
-moz-transform 600ms cubic-bezier(0.55, 0.31, 0.15, 0.93) 0ms,
-webkit-transform 600ms cubic-bezier(0.55, 0.31, 0.15, 0.93) 0ms;
  visibility: visible;
  opacity: 1;
}
  <div class="outer-wrapper">
    <div class="wrapper">
      <div class="background-out"></div>
      <div class="background-over"></div>
      <div class="background-info">
        <div class="text">Text 1</div>
       </div>
    </div>    
  </div>
  <div class="outer-wrapper">
    <div class="wrapper">
      <div class="background-out"></div>
      <div class="background-over"></div>
      <div class="background-info">
        <div class="text">Text 2</div>
       </div>
    </div>    
  </div>
  <div class="outer-wrapper">
    <div class="wrapper">
      <div class="background-out"></div>
      <div class="background-over"></div>
      <div class="background-info">
        <div class="text">Text 2</div>
       </div>
    </div>
  </div>