Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                
  <main>

    <div id="carousel">

       <div class="hideLeft">
        <img src="https://i1.sndcdn.com/artworks-000165384395-rhrjdn-t500x500.jpg">
      </div>

      <div class="prevLeftSecond">
        <img src="https://i1.sndcdn.com/artworks-000185743981-tuesoj-t500x500.jpg">
      </div>

      <div class="prev">
        <img src="https://i1.sndcdn.com/artworks-000158708482-k160g1-t500x500.jpg">
      </div>

      <div class="selected">
        <img src="https://i1.sndcdn.com/artworks-000062423439-lf7ll2-t500x500.jpg">
      </div>

      <div class="next">
        <img src="https://i1.sndcdn.com/artworks-000028787381-1vad7y-t500x500.jpg">
      </div>

      <div class="nextRightSecond">
        <img src="https://i1.sndcdn.com/artworks-000108468163-dp0b6y-t500x500.jpg">
      </div>

      <div class="hideRight">
        <img src="https://i1.sndcdn.com/artworks-000064920701-xrez5z-t500x500.jpg">
      </div>

    </div>

    <div class="buttons">
      <button id="prev">Prev</button>
      <button id="next">Next</button>
    </div>

  </main>
              
            
!

CSS

              
                html, body, main
  width: 100%
  height: 100%
  margin: 0
  padding: 0

#carousel
  position: relative
  height: 400px
  top: 50%
  transform: translateY(-50%)
  overflow: hidden

  div
    position: absolute
    transition: transform 1s, left 1s, opacity 1s, z-index 0s
    opacity: 1

    img
      width: 400px
      transition: width 1s

    &.hideLeft
      left: 0%
      opacity: 0
      transform: translateY(50%) translateX(-50%)

      img
        width: 200px

    &.hideRight
      left: 100%
      opacity: 0
      transform: translateY(50%) translateX(-50%)
      img
        width: 200px

    &.prev
      z-index: 5
      left: 30%
      transform: translateY(50px) translateX(-50%)

      img
        width: 300px

    &.prevLeftSecond
      z-index: 4
      left: 15%
      transform: translateY(50%) translateX(-50%)
      opacity: .7

      img
        width: 200px

    &.selected
      z-index: 10
      left: 50%
      transform: translateY(0px) translateX(-50%)

    &.next
      z-index: 5
      left: 70%
      transform: translateY(50px) translateX(-50%)

      img
        width: 300px

    &.nextRightSecond
      z-index: 4
      left: 85%
      transform: translateY(50%) translateX(-50%)
      opacity: .7

      img
        width: 200px

.buttons
  position: fixed
  left: 50%
  transform: translateX(-50%)
  bottom: 10px

              
            
!

JS

              
                function moveToSelected(element) {

  if (element == "next") {
    var selected = $(".selected").next();
  } else if (element == "prev") {
    var selected = $(".selected").prev();
  } else {
    var selected = element;
  }

  var next = $(selected).next();
  var prev = $(selected).prev();
  var prevSecond = $(prev).prev();
  var nextSecond = $(next).next();

  $(selected).removeClass().addClass("selected");

  $(prev).removeClass().addClass("prev");
  $(next).removeClass().addClass("next");

  $(nextSecond).removeClass().addClass("nextRightSecond");
  $(prevSecond).removeClass().addClass("prevLeftSecond");

  $(nextSecond).nextAll().removeClass().addClass('hideRight');
  $(prevSecond).prevAll().removeClass().addClass('hideLeft');

}

// Eventos teclado
$(document).keydown(function(e) {
    switch(e.which) {
        case 37: // left
        moveToSelected('prev');
        break;

        case 39: // right
        moveToSelected('next');
        break;

        default: return;
    }
    e.preventDefault();
});

$('#carousel div').click(function() {
  moveToSelected($(this));
});

$('#prev').click(function() {
  moveToSelected('prev');
});

$('#next').click(function() {
  moveToSelected('next');
});

              
            
!
999px

Console