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

              
                <nav id="carouselNav" class="carouselNav">
    <div class="carouselNav__listWrapper">
        <ul class="carouselNav__list">
            <li class="carouselNav__listItem">
                <a href="http://www.familycircle.com/holiday/christmas/">Christmas</a>
            </li>
            <li class="carouselNav__listItem">
                <a href="http://www.familycircle.com/holiday/easter/">Easter</a>
            </li>
            <li class="carouselNav__listItem">
                <a href="http://www.familycircle.com/holiday/fathers-day/">Father&#x27;s Day</a>
            </li>
            <li class="carouselNav__listItem">
                <a href="http://www.familycircle.com/holiday/mothers-day/">Mother&#x27;s Day</a>
            </li>
            <li class="carouselNav__listItem">
                <a href="http://www.familycircle.com/holiday/halloween/">Halloween</a>
            </li>
            <li class="carouselNav__listItem">
                <a href="http://www.familycircle.com/holiday/thanksgiving/">Thanksgiving</a>
            </li>
            <li class="carouselNav__listItem">
                <a href="http://www.familycircle.com/holiday/valentines-day/">Valentine&#x27;s Day</a>
            </li>
            <li class="carouselNav__listItem">
                <a href="http://www.familycircle.com/holiday/christmas/">2Christmas</a>
            </li>
            <li class="carouselNav__listItem">
                <a href="http://www.familycircle.com/holiday/easter/">2Easter</a>
            </li>
            <li class="carouselNav__listItem">
                <a href="http://www.familycircle.com/holiday/fathers-day/">2Father&#x27;s Day</a>
            </li>
            <li class="carouselNav__listItem">
                <a href="http://www.familycircle.com/holiday/mothers-day/">2Mother&#x27;s Day</a>
            </li>
            <li class="carouselNav__listItem">
                <a href="http://www.familycircle.com/holiday/halloween/">2Halloween</a>
            </li>
            <li class="carouselNav__listItem">
                <a href="http://www.familycircle.com/holiday/thanksgiving/">2Thanksgiving</a>
            </li>
            <li class="carouselNav__listItem">
                <a href="http://www.familycircle.com/holiday/valentines-day/">2Valentine&#x27;s Day</a>
            </li>
        </ul>
    </div>
    <a class="carouselNav__prev" href="#" role="button"></a>
    <a class="carouselNav__next" href="#" role="button"></a>
</nav>
              
            
!

CSS

              
                @import url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/42886/mtShared.css);
// Colors
$black: #000;
$white: #fff;

$accentColor1: #ec188c;
$accentColor2: #aa0e63;

// Expect color1 to be the lightest.
$color1: #f5f5f5;
$color2: #dedede;
$color3: #9e9e9e;
$color4: #7e7e7e;
$color5: #3e3e3e;
$color6: #2e2e2e;
$carouselNavHeight: 50px;
$carouselNavBackgroundColor: $color2;
$carouselNavTextColor: $black;

$defaultFontSize: 16px;

$icon-chevron-left: "\e905";
$icon-chevron-right: "\e906";

@mixin resetList() {
  list-style: none;
  margin: 0;
  padding: 0;
}

@mixin iconFontFamily($fontFamily: 'MtShared') {
  font-family: $fontFamily;
  speak: none;
  font-style: normal;
  font-weight: normal;
  font-variant: normal;
  text-transform: none;
  line-height: 1;

  /* Better Font Rendering =========== */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}


.carouselNav {
  position: relative;
  height: $carouselNavHeight;
  background: $carouselNavBackgroundColor;
  overflow: hidden;

  &__listWrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }

  &__list {
    @include resetList;
    position: absolute;
    padding: 0 2.5rem;
    top: 0;
    left: 0;
    right: 0;
    height: $carouselNavHeight + 20px;
    overflow-x: scroll;
    word-spacing: 0;
    white-space: nowrap;
    // https://css-tricks.com/snippets/css/momentum-scrolling-on-ios-overflow-elements/
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    background: $carouselNavBackgroundColor;
  }

  &__listItem {
    display: inline-block;
    height: $carouselNavHeight;

    &:not(:last-child) {
      position: relative;
      &:after {
        position: absolute;
        top: 30%;
        right: -1px;
        content: '|';
      }
      a {
        margin-right: 1rem;
        font-size: $defaultFontSize;
      }
    }

    &:not(:first-child) {
      padding-left: 1rem;
    }
  }

  a {
    display: inline-block;
    height: $carouselNavHeight;
    line-height: $carouselNavHeight;
    color: $carouselNavTextColor;
    text-decoration: none;
  }

  &--move {
    transition: left 0.5s;
  }

  &__prev, &__next {
    position: absolute;
    top: 0;
    font-size: 0;
    text-decoration: none;
    color: $carouselNavTextColor;
    height: $carouselNavHeight;
    width: 2rem;

    &:before {
      display: inline-block;
      @include iconFontFamily();
      font-size: 25px;
      line-height: $carouselNavHeight;
    }
  }

  &__prev {
    left: 0;
    padding-left: 0.25rem;
    background: linear-gradient(to left, rgba(255, 255, 255, 0) 0%, $carouselNavBackgroundColor 100%);

    &:before {
      content: $icon-chevron-left;
      right: 0;
    }

    .carouselNav--first & {
      display: none;
    }
  }

  &__next {
    right: 0;
    text-align: right;
    padding-right: 0.25rem;
    background: linear-gradient(to right, rgba(255, 255, 255, 0) 0%, $carouselNavBackgroundColor 100%);

    &:before {
      content: $icon-chevron-right;
    }

    .carouselNav--last & {
      display: none;
    }
  }
}


              
            
!

JS

              
                //http://pure-essence.net/2013/10/25/how-i-made-tiny-carousel-swipeable/
var mdp = {};
(function (mdp) {
  var carouselNav = function (carouselSelector, options) {
    var defaults = {
      viewportSelector: '.carouselNav__listWrapper',
      listSelector: '.carouselNav__list',
      prevSelector: '.carouselNav__prev',
      nextSelector: '.carouselNav__next',
      firstClass: 'carouselNav--first',
      lastClass: 'carouselNav--last',
      itemSelector: 'li',
      selectedSelector: '.carouselNav__listItem--selected',
      scrollAnimationDuration: 500, // ms
      defaultScrollDistance: 200,
      offset: 20,
    };

    if (options) {
      // Allow option overrides.
      options = Object.assign(defaults, options);
    }
    else {
      options = defaults;
    }
    
    function offset(elt) {
      var rect = elt.getBoundingClientRect(), bodyElt = document.body;

      return {
        top: rect.top + bodyElt.scrollTop,
        left: rect.left + bodyElt.scrollLeft
      }
    }
    
    // Robert Penner's easeInOutQuad - http://robertpenner.com/easing/
    function easeInOutQuad(t, b, c, d)  {
      t /= d / 2;
      if(t < 1) {
        return c / 2 * t * t + b;
      }
      t--;
      return -c / 2 * (t * (t - 2) - 1) + b;
    }
    
    function CarouselSwipeable(root, options) {
      var wrapper = root.querySelector(options.listSelector);
      var selectedElement = wrapper.querySelector(options.selectedSelector);
      var items = wrapper.querySelectorAll(options.itemSelector);
      var minItem = items[0];
      var maxItem = items[items.length - 1];

      root.classList.remove(options.firstClass);
      root.classList.remove(options.lastClass);

      if (selectedElement) {
        if (minItem !== selectedElement) {
          var childPos = offset(selectedElement);
          var parentPos = offset(wrapper);
          var childOffset = {
            left: childPos.left - parentPos.left
          };

          var startPos = childOffset.left;
          if (maxItem !== selectedElement) {
            startPos = startPos - options.offset;
          }
          scroll('right', wrapper, startPos);
        }
        else {
          root.classList.add(options.firstClass);
        }
      }
      else {
        checkEnds();
      }

      var scrollDone;
      wrapper.addEventListener('scroll', function () {
        clearTimeout(scrollDone);
        scrollDone = setTimeout(checkEnds, 100);
      });
      
      var resizeDone;
      window.addEventListener('resize', function() {
        clearTimeout(resizeDone);
        resizeDone = setTimeout(checkEnds, 500);
      });
      root.querySelector(options.prevSelector).addEventListener('click', function (e) {
        e.preventDefault();
        e.stopPropagation();
        scroll('left', wrapper, getDistance());
      });
      root.querySelector(options.nextSelector).addEventListener('click', function (e) {
        e.preventDefault();
        e.stopPropagation();
        scroll('right', wrapper, getDistance());
      });

      function scroll(direction, innerWrapper, distance) {
        if (!distance) {
          distance = options.defaultScrollDistance;
        }
        
        if ('left' === direction) {
          distance = -distance;
        }

        smoothScroll(innerWrapper, distance);
      }

      function checkEnds() {
        root.classList.remove(options.firstClass);
        root.classList.remove(options.lastClass);
        markFirst();
        markLast();
      }

      function markFirst() {
        var viewport = root.querySelector(options.viewportSelector);
        var minItemOffsetLeft = offset(minItem).left;
        var minItemPositionLeft = minItemOffsetLeft - offset(viewport).left;
        if (minItemPositionLeft >= 0) {
          root.classList.add(options.firstClass);
        }
      }

      function markLast() {
        var viewport = root.querySelector(options.viewportSelector);
        var maxItemOffsetLeft = offset(maxItem).left;
        var maxItemPositionLeft = maxItemOffsetLeft - offset(viewport).left + maxItem.offsetWidth;
        if (maxItemPositionLeft <= viewport.offsetWidth) {
          root.classList.add(options.lastClass);
        }
      }

      function getDistance() {
        var viewport = root.querySelector(options.viewportSelector);
        return viewport.offsetWidth - options.offset;
      }
      
      // Inspired by https://github.com/sitepoint-editors/smooth-scrolling/blob/gh-pages/jump.js
      function smoothScroll(wrapper, scrollDistance) {
        var start = wrapper.scrollLeft;
        var distance = scrollDistance;
        var duration = options.scrollAnimationDuration;
        var timeStart, timeElapsed;
        
        requestAnimationFrame(function(time) { timeStart = time; loop(time); });

        function loop(time) {
          timeElapsed = time - timeStart;

          wrapper.scrollLeft = easeInOutQuad(timeElapsed, start, distance, duration);

          if (timeElapsed < duration) {
            requestAnimationFrame(loop);
          }
          else {
            end();
          }
        }

        function end() {
          wrapper.scrollLeft = start + distance;
          checkEnds();
        }
      }
    }
    
    var carousels = document.querySelectorAll(carouselSelector);
    for (var i = 0; i < carousels.length; i++) {
      var carousel = carousels[i];
      new CarouselSwipeable(carousel, options);
    }
  };

  mdp.carouselNav = carouselNav;
  mdp.carouselNav('#carouselNav');
})(mdp || {});



              
            
!
999px

Console