cssAudio - ActiveCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class="wrapper wrapper--demo">
	<div class="carousel">
		<div class="carousel__content">
			<div class="item">
        <p class="title">First</p>
        <img src="http://placehold.it/1800x850/70AD96/FFF&text=&nbsp;" alt="">
      </div>
			<div class="item">
        <p class="title">Second</p>
        <img src="http://placehold.it/1800x850/EA4E23/FFF&text=&nbsp;" alt="">
      </div>
			<div class="item">
        <p class="title">Third</p>
        <img src="http://placehold.it/1800x850/9BA452/FFF&text=&nbsp;" alt="">
      </div>
			<div class="item">
        <p class="title">Fourth</p>
        <img src="http://placehold.it/1800x850/472D38/FFF&text=&nbsp;" alt="">
      </div>
			<div class="item">
        <p class="title">Fifth</p>
        <img src="http://placehold.it/1800x850/F77C85/FFF&text=&nbsp;" alt="">
      </div>
			<div class="item">
        <p class="title">Sixth</p>
        <p class="title title--sub">Last Item</p>
        <img src="http://placehold.it/1800x850/00FFAE/FFF&text=&nbsp;" alt="">
      </div>
		</div>
    
    <div class="carousel__nav">
      <a href="#" class="nav nav--left">Previous</a>
      <a href="#" class="nav nav--right">Next</a>
    </div>
    
	</div>
</div>
            
          
!
            
              @import "compass/css3";

* {
  -webkit-box-sizing: border-box;
	-moz-box-sizing: border-box;
	box-sizing: border-box;
}

body, html {
  font-family: "europa-1","europa-2", sans-serif;
  overflow: hidden;
}

.wrapper {
  max-width: 940px;
  width: 100%;
  position: relative;
  overflow: hidden;
  margin: 0 auto;
}

/**
 * Use this wrapper only for demo purposes
 * So you can show the items outside the wrapper
 */
.wrapper--demo {
  overflow: visible;
  
  &:after, &:before {
    content: "";
    position: absolute;
    width: 800px;
    height: 100%;
    top: 0;
    left: 100%;
    background: rgba(255, 255, 255, .8);
    z-index: 2;
  }
  &:before {
    left: -800px;
  }
}

.carousel {
  width: 100%;
  position: relative;
  
  .carousel__content {
    width: auto;
    position: relative;
    overflow: hidden;
    -webkit-backface-visibility: hidden;
    -webkit-transition: translate3d(0,0,0);
    
    .item {
      display: block;
      float: left;
      width: 100%;
      position: relative;
      
      .title {
        position: absolute;
        top: 50%;
        left: 0;
        margin: -33px 0 0 0;
        padding: 0;
        font-size: 3rem;
        width: 100%;
        text-align: center;
        letter-spacing: .3rem;
        color: #FFF;
      }
      .title--sub {
        margin-top: 20px;
        font-size: 1.2em;
        opacity: .5;
      }
      img {
        width: 100%;
        max-width: 100%;
        display: block;
      }
    }
  }
  
  .carousel__nav {
    position: absolute;
    width: 100%;
    top: 50%;
    margin-top: -17px;
    left: 0;
    z-index: 1;
    
    .nav {
      position: absolute;
      top: 0;
      color: #000;
      background: #FFF;
      padding: 8px 12px;
      font-weight: bold;
      text-decoration: none;
      font-size: .8rem;
      transition: padding .25s ease;
      &:hover { padding:8px 20px; }
    }
    
    .nav--left {
      border-radius: 0px 3px 3px 0px;
    }
    
    .nav--right {
      right: 0;
      border-radius: 3px 0px 0px 3px;
    }
  }
}
            
          
!
            
              # Carousel variables
carouselContent = $(".carousel__content")
carouselIndex = 0
carouselLength = carouselContent.children().length

isAnimating = false
itemWidth = 100 / carouselLength
firstItem = $(carouselContent.children()[0])
lastItem = $(carouselContent.children()[carouselLength - 1])
firstClone = null
lastClone = null

# Apply the 3D transformations to avoid a white blink when you slide for the first time
carouselContent.css "width", carouselLength * 100 + "%"
carouselContent.transition { x:"#{carouselIndex * -itemWidth}%" }, 0

$.each carouselContent.children(), -> $(@).css "width", itemWidth + "%"
  
# Click on the "Previous" button
$(".nav--left").on "click", ->
  return if isAnimating
  isAnimating = true
    
  carouselIndex--
  if carouselIndex == -1
    lastItem.prependTo carouselContent
    carouselContent.transition { x:"#{(carouselIndex + 2) * -itemWidth}%" }, 0
    carouselContent.transition { x:"#{(carouselIndex + 1) * -itemWidth}%" }, 1000, "easeInOutExpo", ->
      carouselIndex = carouselLength - 1
      lastItem.appendTo carouselContent
      carouselContent.transition { x:"#{(carouselIndex) * -itemWidth}%" }, 0
      isAnimating = false
  else
    carouselContent.transition { x:"#{carouselIndex * -itemWidth}%" }, 1000, "easeInOutExpo", -> isAnimating = false

# Click on the "Next" button
$(".nav--right").on "click", ->
  return if isAnimating
  isAnimating = true
    
  carouselIndex++
    
  carouselContent.transition { x:"#{carouselIndex * -itemWidth}%" }, 1000, "easeInOutExpo", ->
    isAnimating = false
    if firstClone
      carouselIndex = 0
      carouselContent.transition { x:"#{(carouselIndex) * -itemWidth}%" }, 0
      firstClone.remove()
      firstClone = null
      
      carouselLength = carouselContent.children().length
      itemWidth = 100 / carouselLength
      carouselContent.css "width", carouselLength * 100 + "%"
      $.each carouselContent.children(), -> $(@).css "width", itemWidth + "%"
      return
        
    if carouselIndex == carouselLength - 1
      carouselLength++
      itemWidth = 100 / carouselLength
      
      firstClone = firstItem.clone()
      firstClone.addClass "clone"
      firstClone.appendTo carouselContent
       
      carouselContent.css "width", carouselLength * 100 + "%"
      $.each carouselContent.children(), -> $(@).css "width", itemWidth + "%"
      carouselContent.transition { x:"#{(carouselIndex) * -itemWidth}%" }, 0
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console