Creating A 3D Image Carousel / Rotator with jQuery and CSS3 - jCarrousel

File Size: 488 KB
Views Total: 4415
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Creating A 3D Image Carousel / Rotator with jQuery and CSS3 - jCarrousel

jCarrousel is a simple and easy-to-use jQuery plugin used to rotate through a group of images (or html objects) like a 3D carousel / rotator. Powered by modernizr.js and CSS3 transform & perspective properties.

How to use it:

1. Include the necessary jQuery library and modernizr.js JavaScript library on the webpage.

<script src="path/to/modernizr.custom.53451.js"></script>
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>

2. Include the carrousel.min.js after jQuery library.

<script src="path/to/carrousel.min.js"></script>

3. Add a group of images with a bullets pagination to the carousel / rotator.

<section id="dg-container" class="dg-container">
  <div class="dg-wrapper">
      <a href="#">
          <img src="images/1.jpg">
      </a>
      <a href="#">
          <img src="images/2.jpg">
      </a>
      <a href="#">
          <img src="images/3.jpg">
      </a>
      <a href="#">
          <img src="images/4.jpg">
      </a>
      <a href="#">
          <img src="images/5.jpg">
      </a>
  </div>
  <ol class="button" id="lightButton">
      <li index="0">
      <li index="1">
      <li index="2">
      <li index="3">
      <li index="4">
  </ol>
  <nav>
      <span class="dg-prev"></span>
      <span class="dg-next"></span>
  </nav>
</section>

4. The required CSS / CSS3 styles.

.dg-container {
  position: relative;
  width: 100%;
  height: 450px;
}

.dg-wrapper {
  width: 700px;
  height: 450px;
  margin: 0 auto;
  position: relative;
  transform-style: preserve-3d;
  perspective: 1000px;
}

.dg-wrapper a {
  width: 700px;
  height: 450px;
  display: block;
  position: absolute;
  left: 0;
  top: 0;
}

.dg-wrapper a:before {
  position: absolute;
  display: block;
  content: "";
  width: 700px;
  height: 450px;
  box-shadow: 0px 2px 0px 0px rgba(255, 255, 255, 0.10) inset, 0px 0px 0px 1px rgba(0, 0, 0, 0.20) inset;
  border-radius: 4px;
}

.dg-wrapper a:first-child { z-index: 2; }

.dg-wrapper a img {
  display: block;
  box-shadow: 0px 1px 3px 0px rgba(0, 0, 0, 0.20);
  border-radius: 4px;
  width: 700px;
  height: 450px;
  background: #fff;
}

.dg-wrapper a.dg-transition { transition: all 0.5s ease-in-out; }

.dg-container nav { display: none; }

.dg-container nav span:hover { opacity: 1; }

.dg-container nav span.dg-next {
  background-position: top right;
  margin-left: 10px;
}

.dg-container #lightButton2 { bottom: 20px; }

.dg-container .button {
  position: relative;
  z-index: 5;
}

.dg-container .button li {
  cursor: pointer;
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 5px;
  background: rgba(255, 255, 255, 0.30);
  border: 1px solid rgba(0, 0, 0, 0.20);
}

.dg-container .button .light { background: #01BDFF; }

5. Initialize the plugin.

('#dg-container').carrousel();

6. Override the default option values to customize the plugin.

('#dg-container').carrousel({

  // initial slide
  current: 0, 

  // autoplay
  autoplay: true,

  // autoplay interval in ms
  interval: 3000 
  
});

Change log:

2015-10-02

  • improvement.

This awesome jQuery plugin is developed by DIYgod. For more Advanced Usages, please check the demo page or visit the official website.