3D Perspective Carousel with CSS3 Transforms

Category: CSS & CSS3 , Recommended , Slider | August 1, 2015
Author: edmundojr
Views Total: 4,666
Official Page: Go to website
Last Update: August 1, 2015
License: MIT

Preview:

3D Perspective Carousel with CSS3 Transforms

Description:

A pure CSS 3D perspective carousel that automatically rotate through a group of html content using CSS3 transforms.

How to use it:

Build the html structure for the carousel.

<div class="carousel">
  <div class="carousel-content">
    <div class="carousel-item"></div>
    <div class="carousel-item"></div>
    <div class="carousel-item"></div>
  </div>
</div>

The primary CSS / CSS3 style rules for the carousel.

.carousel {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 190px;
  height: 210px;
  margin: 0;
  -webkit-perspective: 800px;
  perspective: 800px;
  -webkit-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}

.carousel-content {
  position: absolute;
  width: 100%;
  height: 100%;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  -webkit-transform: translateZ(-182px) rotateY(0);
  transform: translateZ(-182px) rotateY(0);
  -webkit-animation: carousel 10s infinite cubic-bezier(1, 0.015, 0.295, 1.225) forwards;
  animation: carousel 10s infinite cubic-bezier(1, 0.015, 0.295, 1.225) forwards;
}

.carousel-item {
  position: absolute;
  top: 0;
  left: 0;
  width: 190px;
  height: 210px;
  border-radius: 6px;
}

.carousel-item:nth-child(1) {
  background: rgba(252, 192, 77, 0.9);
  -webkit-transform: rotateY(0) translateZ(182px);
  transform: rotateY(0) translateZ(182px);
}

.carousel-item:nth-child(2) {
  background: rgba(49, 192, 204, 0.9);
  -webkit-transform: rotateY(120deg) translateZ(182px);
  transform: rotateY(120deg) translateZ(182px);
}

.carousel-item:nth-child(3) {
  background: rgba(236, 233, 242, 0.9);
  -webkit-transform: rotateY(240deg) translateZ(182px);
  transform: rotateY(240deg) translateZ(182px);
}

Create the 3D transform effects.

@-webkit-keyframes 
carousel {  0%, 17.5% {
 -webkit-transform: translateZ(-182px) rotateY(0);
 transform: translateZ(-182px) rotateY(0);
}
 27.5%, 45% {
 -webkit-transform: translateZ(-182px) rotateY(-120deg);
 transform: translateZ(-182px) rotateY(-120deg);
}
 55%, 72.5% {
 -webkit-transform: translateZ(-182px) rotateY(-240deg);
 transform: translateZ(-182px) rotateY(-240deg);
}
 82.5%, 100% {
 -webkit-transform: translateZ(-182px) rotateY(-360deg);
 transform: translateZ(-182px) rotateY(-360deg);
}
}
 @keyframes 
carousel {  0%, 17.5% {
 -webkit-transform: translateZ(-182px) rotateY(0);
 transform: translateZ(-182px) rotateY(0);
}
 27.5%, 45% {
 -webkit-transform: translateZ(-182px) rotateY(-120deg);
 transform: translateZ(-182px) rotateY(-120deg);
}
 55%, 72.5% {
 -webkit-transform: translateZ(-182px) rotateY(-240deg);
 transform: translateZ(-182px) rotateY(-240deg);
}
 82.5%, 100% {
 -webkit-transform: translateZ(-182px) rotateY(-360deg);
 transform: translateZ(-182px) rotateY(-360deg);
}
}

You Might Be Interested In:


Leave a Reply