2 mar 2015

Trochę animacji w CSS3 - kafelki

Animacja "kafelków" w css3

Trochę css

.box-flip {
  width: 999px;
  height: 390px;

}

.box-flip .front {
  line-height: 194px;
  text-align: center;
  font-weight: bold;
  font-size: 40px;
  font-family: Helvetica, Arial, Verdana, sans-serif;
  color: #c6001f;
  border: 1px solid;

}

.box-flip .item {
  float: left;
  cursor: pointer;
}

.box-flip .item .row-item {
  -webkit-transform-style: preserve-3d;
  -moz-transform-style: preserve-3d;
  -o-transform-style: preserve-3d;
  -ms-transform-style: preserve-3d;
  transform-style: preserve-3d;
  -webkit-transition: 0.6s -webkit-transform;
  -moz-transition: 0.6s -moz-transform;
  -o-transition: 0.6s -o-transform;
  -ms-transition: 0.6s -o-transform;
  transition: 0.6s transform;
  position: relative;
}

.box-flip .item:hover .row-item {
  -webkit-transform: rotateY(.5turn);
  -moz-transform: rotateY(.5turn);
  -o-transform: rotateY(.5turn);
  -ms-transform: rotateY(.5turn);
  transform: rotateY(.5turn);
}

.box-flip .item .row-item>.back {
  overflow: hidden;
  opacity: 0;
  -webkit-transform: scale(0.4) rotateY(0.5turn) translateZ(1px);
  -moz-transform: scale(0.4) rotateY(0.5turn) translateZ(1px);
  -o-transform: scale(0.4) rotateY(0.5turn) translateZ(1px);
  -ms-transform: scale(0.4) rotateY(0.5turn) translateZ(1px);
  transform: scale(0.4) rotateY(0.5turn) translateZ(1px);
  -webkit-transition: 0.4s .075s opacity, 0.2s -webkit-transform;
  -moz-transition: 0.4s .075s opacity, 0.2s -moz-transform;
  -o-transition: 0.4s .075s opacity, 0.2s -o-transform;
  -ms-transition: 0.4s .075s opacity, 0.2s -ms-transform;
  transition: 0.4s .075s opacity, 0.2s transform;
  display: block;
}

.box-flip .item .row-item>.back {
  display: none\9;
}

.box-flip .item:hover .row-item>.back {
  overflow: visible;
  opacity: 1;
  -webkit-transform: scale(1) rotateY(0.5turn) translateZ(1px);
  -moz-transform: scale(1) rotateY(0.5turn) translateZ(1px);
  -o-transform: scale(1) rotateY(0.5turn) translateZ(1px);
  -ms-transform: scale(1) rotateY(0.5turn) translateZ(1px);
  transform: scale(1) rotateY(0.5turn) translateZ(1px);
}

.box-flip .item:hover .row-item>.back {
  display: block\9;
}

.box-flip .item {
  -webkit-perspective: 1200px;
  -moz-perspective: 1200px;
  -o-perspective: 1200px;
  -ms-perspective: 1200px;
  perspective: 1200px;
  overflow: visible;
}

.box-flip div.back {
  display: none;
  position: absolute;
  left: 0;
  top: 0;
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  background: #f7732f;
  z-index: 2;
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.8);
  line-height: 194px;
  text-align: center;
}

.box-flip .box-a {
  width: 333px;
  height: 195px;
  margin-right: 2px;
  margin-bottom: 2px;
}

.box-flip .box-a .back {
  width: 333px;
  height: 195px;
}

.box-flip .box-b {
  width: 664px;
  height: 195px;
  margin-bottom: 2px;
}

.box-flip .box-b .back {
  width: 664px;
  height: 195px;
}

.box-flip .box-c {
  width: 333px;
  height: 194px;
  margin-right: 2px;
}

.box-flip .box-c .back {
  width: 333px;
  height: 194px;
}

.box-flip .box-d {
  width: 331px;
  height: 194px;
  margin-right: 2px;
}

.box-flip .box-d .back {
  width: 331px;
  height: 194px;
}

.box-flip .box-e {
  width: 331px;
  height: 194px;
}

.box-flip .box-e .back {
  width: 331px;
  height: 194px;
}

Teraz lekkie html 😉

<div class="box-flip">
  <div class="item box-a">
    <div class="row-item">
      <div class="front">4 170 858</div>
      <div class="back"><a href="http://www.pkt.pl">Jakis tam tekst 01</a></div>
    </div>
  </div>
  <div class="item box-b">
    <div class="row-item">
      <div class="front">10 804 978</div>
      <div class="back">Jakis tam tekst 02</div>
    </div>
  </div>
  <div class="item box-c">
    <div class="row-item">
      <div class="front">6 411 073</div>
      <div class="back">Jakis tam tekst 03</div>
    </div>
  </div>
  <div class="item box-d">
    <div class="row-item">
      <div class="front">995</div>
      <div class="back">Jakis tam tekst 04</div>
    </div>
  </div>
  <div class="item box-e">
    <div class="row-item">
      <div class="front">3 582 071</div>
      <div class="back">Jakis tam tekst 05</div>
    </div>
  </div>
</div>

Po najechaniu mamy animację, kafelek się odwraca i widzimy tekst. Oczywiście nie wszędzie to działa i czasami brak jest animacji jedynie pojawia się "druga strona" z tekstem. Można sprawdzić na tej stronie która przeglądarka obsługuje te wszystkie "wymyślne" style 😉

Poniżej w pełni działająca wersja.