Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Demo of Image Slideshow</h1>
<ul>
  <li><a href='https://codepen.io/makzan/pen/zxmMvR' target='_top'>Step 1: Images list</a></li>
  <li><a href='https://codepen.io/makzan/pen/pvxQEP' target='_top'>Step 2: Basic CSS</a></li>
  <li><a href='https://codepen.io/makzan/pen/RNeqGz' target='_top'>Step 3: Adding jQuery</a></li>
  <li><a href='https://codepen.io/makzan/pen/Pwyxbw' target='_top'>Step 4: Animating with CSS</a></li>
  <li><a href='https://codepen.io/makzan/pen/KwGrNW' target='_top'>Extra: Animating style 2</a></li>
  <li><strong>Extra: Animating style 3</strong></li>
</ul>
<ul class='slideshow'>
  <li><img src='http://unsplash.it/500/200?image=151' alt='Placeholder image'></li>
  <li><img src='http://unsplash.it/500/200?image=152' alt='Placeholder image'></li>
  <li><img src='http://unsplash.it/500/200?image=153' alt='Placeholder image'></li>
  <li><img src='http://unsplash.it/500/200?image=154' alt='Placeholder image'></li>
  <li><img src='http://unsplash.it/500/200?image=155' alt='Placeholder image'></li>
</ul>

<p><small>This is a demo by Makzan. Created for the <a href='https://gum.co/jquery101'>Beginning jQuery</a> course.</small></p>

              
            
!

CSS

              
                /* Slideshow controlling */
.slideshow {
  perspective: 700px;
}
.slideshow li {
  /* easing function is customized in http://matthewlein.com/ceaser/ */
  transition: all 0.45s cubic-bezier(0.070, 0.405, 0.175, 1.365);
  transform-origin: 0 0;
}
.slideshow li.ready-to-show {
  transform: rotateX(90deg);
  transition: none;
}
.slideshow li.showing {
  transform: rotateX(0);
}
.slideshow li.after-show {
  transform: rotateX(-90deg);  
  opacity: 0;
  /* a very short delay to connect the next image and current-fading-out image. */
  transition-delay: .15s;
}

/* Slideshow layout style */
.slideshow {
  overflow: hidden;  
  width: 500px;
  height: 200px;
  position: relative;
  background: BLACK;
}
ul.slideshow {
  margin: 0;
  padding: 0;
  list-style: none;
}
.slideshow li {
  position: absolute;  
}

/* Not related */
.slideshow {
  border: 3px solid BLACK;
  border-radius: 5px;
}

body {
  padding: 50px;
}
              
            
!

JS

              
                var images = $('.slideshow li');

// make all images in `before` state
images.addClass('ready-to-show');

// current index default 0.
var currentIndex = 0;

// showing 1 image by default.
images.eq(currentIndex).removeClass().addClass('showing');

function nextSlide() {
  // move all existing `after` image to ready-to-show state.
  $('.slideshow li.after-show').removeClass().addClass('ready-to-show');
  
  // find the current image and move it to after-show.
	images.eq(currentIndex).removeClass().addClass('after-show');
  
  // increase currentIndex by 1. Reset to 0 if the index exceeds count of images.
  currentIndex = (currentIndex + 1 ) % images.length;
  
  // move next image to current.
  images.eq(currentIndex).removeClass().addClass('showing');  
}

setInterval(nextSlide, 3000);
              
            
!
999px

Console