cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

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.

            
              <h1>Flickity - custom navigation UI with vanilla JS</h1>

<div class="carousel">
  <div class="carousel-cell"></div>
  <div class="carousel-cell"></div>
  <div class="carousel-cell"></div>
  <div class="carousel-cell"></div>
  <div class="carousel-cell"></div>
</div>

<div class="button-row">
  <button class="button button--previous">&larr;</button>
  <div class="button-group button-group--cells">
    <button class="button is-selected">1</button>
    <button class="button">2</button>
    <button class="button">3</button>
    <button class="button">4</button>
    <button class="button">5</button>
  </div>
  <button class="button button--next">&rarr;</button>
</div>

            
          
!
            
              /* external css: flickity.css */

* { box-sizing: border-box; }

body { font-family: sans-serif; }

.carousel {
  background: #FAFAFA;
  margin-bottom: 20px;
}

.carousel-cell {
  width: 66%;
  height: 200px;
  margin-right: 10px;
  background: #8C8;
  border-radius: 5px;
  counter-increment: carousel-cell;
}

/* cell number */
.carousel-cell:before {
  display: block;
  text-align: center;
  content: counter(carousel-cell);
  line-height: 200px;
  font-size: 80px;
  color: white;
}

.button {
  display: inline-block;
  padding: 10px 22px;
  font-size: 18px;
  border: 1px solid #DDD;
  border-radius: 6px;
  background-color: #FAFAFA;
  background-image: linear-gradient( hsla(0, 0%, 0%, 0), hsla(0, 0%, 0%, 0.1) )
}

.button:hover {
  background-color: white;
  border-color: #BBB;
  cursor: pointer;
}

.button:focus {
  outline: thin dotted;
  outline: 5px auto -webkit-focus-ring-color;
  outline-offset: -2px;
  background-color: white;
}

.button:active {
  background-color: #EEE;
  box-shadow: inset 0 2px 10px hsla(0, 0%, 0%, 0.3);
}

.button.is-selected {
  background-color: #09F;
  color: white;
}

/* ---- button-group ---- */

.button-group {
  display: inline-block;
  vertical-align: bottom;
}

.button-group:after {
  content: '';
  display: block;
  clear: both;
}

.button-group .button {
  float: left;
  border-radius: 0;
  border-right-width: 0;
}

.button-group .button:first-child {
  border-radius: 6px 0 0 6px;
}

.button-group .button:last-child {
  border-radius: 0 6px 6px 0;
  border-right-width: 1px;
}

/* ---- button-row ---- */

.button-row {
  text-align: center;
}

            
          
!
            
              // external js: flickity.pkgd.js

var utils = window.fizzyUIUtils;

var carousel = document.querySelector('.carousel');
var flkty = new Flickity( carousel, {
  prevNextButtons: false,
  pageDots: false
});
// elements
var cellsButtonGroup = document.querySelector('.button-group--cells');
var cellsButtons = utils.makeArray( cellsButtonGroup.children );

// update buttons on select
flkty.on( 'select', function() {
  var previousSelectedButton = cellsButtonGroup.querySelector('.is-selected');
  var selectedButton = cellsButtonGroup.children[ flkty.selectedIndex ];
  previousSelectedButton.classList.remove('is-selected');
  selectedButton.classList.add('is-selected');
});

// cell select
cellsButtonGroup.addEventListener( 'click', function( event ) {
  if ( !matchesSelector( event.target, '.button' ) ) {
    return;
  }
  var index = cellsButtons.indexOf( event.target );
  flkty.select( index );
});
// previous
var previousButton = document.querySelector('.button--previous');
previousButton.addEventListener( 'click', function() {
  flkty.previous();
});
// next
var nextButton = document.querySelector('.button--next');
nextButton.addEventListener( 'click', function() {
  flkty.next();
});

            
          
!
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