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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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

              
                <section class="cd-title">
  <h1>Animated Headlines</h1>
</section>

<ul class="cd-filter">
  <li>
    <input type="radio" id="rotate-1" name="cd-animation-type" checked>
    <label for="rotate-1">Rotate 1</label>
  </li>
  <li>
    <input type="radio" id="rotate-2" name="cd-animation-type">
    <label for="rotate-2">Rotate 2</label>
  </li>
  <li>
    <input type="radio" id="loading-bar" name="cd-animation-type">
    <label for="loading-bar">Loading Bar</label>
  </li>
  <li>
    <input type="radio" id="slide" name="cd-animation-type">
    <label for="slide">Slide</label>
  </li>
  <li>
    <input type="radio" id="scale" name="cd-animation-type">
    <label for="scale">Scale</label>
  </li>
</ul>

<section class="cd-intro">
  <h1 class="cd-headline rotate-1">
    <span>My favourite game is</span>
    <span class="cd-words-wrapper">
      <b class="is-visible">ninepins</b>
      <b>bowling</b>
      <b>skittles</b>
    </span>
  </h1>
</section>

              
            
!

CSS

              
                body {
  font-size: 1.3rem;
  font-family: 'Roboto', sans-serif;
  font-weight: 400;
  color: #fff;
  background-color: #E10E49;
}

.cd-title {
  position: relative;
  height: 80px;
  line-height: 80px;
  text-align: center;
}
.cd-title h1 {
  font-size: 2rem;
}

.cd-filter, .cd-intro {
  width: 90%;
  text-align: center;
}

.cd-intro {
  margin: 2em auto;
}

.cd-filter {
  margin: 0 auto;
  text-align: center;
}
.cd-filter li {
  position: relative;
  display: inline-block;
  margin: 0;
}
.cd-filter input {
  position: absolute;
  left: 0;
  top: 0;
  opacity: 0;
}

.cd-filter input:checked + label {
  border-color: #e6d925;
  color: rgba(255, 255, 255, 1);
}
.cd-filter label {
  border-color: #e10e49;
  border-style: solid;
  border-width: 0 0 2px;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  display: inline-block;
  margin: 0;
  padding: 0.4em 0.6em;
}
.cd-filter label:hover {
  border-color: rgba(255, 255, 255, 0.7);
}

.cd-headline {
  font-size: 5rem;
  font-weight: 300;
  line-height: 1;
}

.cd-words-wrapper {
  display: inline-block;
  position: relative;
  text-align: left;
}
.cd-words-wrapper b {
  display: inline-block;
  position: absolute;
  white-space: nowrap;
  left: 0;
  top: 0;
}
.cd-words-wrapper b.is-visible {
  position: relative;
}

/* -------------------------------- 

xrotate-1 

-------------------------------- */
.cd-headline.rotate-1 .cd-words-wrapper {
  perspective: 300px;
}
.cd-headline.rotate-1 b {
  opacity: 0;
  transform-origin: 50% 100%;
  transform: rotateX(180deg);
}
.cd-headline.rotate-1 b.is-visible {
  opacity: 1;
  transform: rotateX(0deg);
  animation: cd-rotate-1-in 1.2s;
}
.cd-headline.rotate-1 b.is-hidden {
  transform: rotateX(180deg);
  animation: cd-rotate-1-out 1.2s;
}
@keyframes cd-rotate-1-in {
  0% {
    transform: rotateX(180deg);
    opacity: 0;
  }
  35% {
    transform: rotateX(120deg);
    opacity: 0;
  }
  65% {
    opacity: 0;
  }
  100% {
    transform: rotateX(360deg);
    opacity: 1;
  }
}
@keyframes cd-rotate-1-out {
  0% {
    transform: rotateX(0deg);
    opacity: 1;
  }
  35% {
    transform: rotateX(-40deg);
    opacity: 1;
  }
  65% {
    opacity: 0;
  }
  100% {
    transform: rotateX(180deg);
    opacity: 0;
  }
}

/* -------------------------------- 

xrotate-2 

-------------------------------- */
.cd-headline.rotate-2 .cd-words-wrapper {
  perspective: 300px;
}
.cd-headline.rotate-2 i, .cd-headline.rotate-2 em {
  display: inline-block;
  backface-visibility: hidden;
}
.cd-headline.rotate-2 i {
  transform-style: preserve-3d;
  transform: translateZ(-20px) rotateX(90deg);
  opacity: 0;
}
.is-visible .cd-headline.rotate-2 i {
  opacity: 1;
}
.cd-headline.rotate-2 i.in {
  animation: cd-rotate-2-in 0.4s forwards;
}
.cd-headline.rotate-2 i.out {
  animation: cd-rotate-2-out 0.4s forwards;
}
.cd-headline.rotate-2 em {
  transform: translateZ(20px);
}

.no-csstransitions .cd-headline.rotate-2 i {
  transform: rotateX(0deg);
  opacity: 0;
}
.no-csstransitions .cd-headline.rotate-2 i em {
  transform: scale(1);
}

.no-csstransitions .cd-headline.rotate-2 .is-visible i {
  opacity: 1;
}

@keyframes cd-rotate-2-in {
  0% {
    opacity: 0;
    transform: translateZ(-20px) rotateX(90deg);
  }
  60% {
    opacity: 1;
    transform: translateZ(-20px) rotateX(-10deg);
  }
  100% {
    opacity: 1;
    transform: translateZ(-20px) rotateX(0deg);
  }
}

@keyframes cd-rotate-2-out {
  0% {
    opacity: 1;
    transform: translateZ(-20px) rotateX(0);
  }
  60% {
    opacity: 0;
    transform: translateZ(-20px) rotateX(-100deg);
  }
  100% {
    opacity: 0;
    transform: translateZ(-20px) rotateX(-90deg);
  }
}

/* -------------------------------- 

xloading-bar 

-------------------------------- */
.cd-headline.loading-bar span {
  display: inline-block;
  padding: .2em 0;
}
.cd-headline.loading-bar .cd-words-wrapper {
  overflow: hidden;
  vertical-align: top;
}
.cd-headline.loading-bar .cd-words-wrapper::after {
  /* loading bar */
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 0;
  background: #E6D925;
  z-index: 2;
  transition: width 0.3s -0.1s;
}
.cd-headline.loading-bar .cd-words-wrapper.is-loading::after {
  width: 100%;
  transition: width 3s;
}
.cd-headline.loading-bar b {
  top: .2em;
  opacity: 0;
  transition: opacity 0.3s;
}
.cd-headline.loading-bar b.is-visible {
  opacity: 1;
  top: 0;
}

/* -------------------------------- 

xslide 

-------------------------------- */
.cd-headline.slide span {
  display: inline-block;
  padding: .2em 0 .3em;
}
.cd-headline.slide .cd-words-wrapper {
  overflow: hidden;
  vertical-align: top;
}
.cd-headline.slide b {
  opacity: 0;
  top: .2em;
}
.cd-headline.slide b.is-visible {
  top: 0;
  opacity: 1;
  animation: slide-in 0.6s;
}
.cd-headline.slide b.is-hidden {
  animation: slide-out 0.6s;
}

@keyframes slide-in {
  0% {
    opacity: 0;
    transform: translateY(-100%);
  }
  60% {
    opacity: 1;
    transform: translateY(20%);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes slide-out {
  0% {
    opacity: 1;
    transform: translateY(0);
  }
  60% {
    opacity: 0;
    transform: translateY(120%);
  }
  100% {
    opacity: 0;
    transform: translateY(100%);
  }
}

/* -------------------------------- 

xscale 

-------------------------------- */
.cd-headline.scale i {
  display: inline-block;
  opacity: 0;
  transform: scale(0);
}
.is-visible .cd-headline.scale i {
  opacity: 1;
}
.cd-headline.scale i.in {
  animation: scale-up 0.6s forwards;
}
.cd-headline.scale i.out {
  animation: scale-down 0.6s forwards;
}

.no-csstransitions .cd-headline.scale i {
  transform: scale(1);
  opacity: 0;
}

.no-csstransitions .cd-headline.scale .is-visible i {
  opacity: 1;
}

@keyframes scale-up {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  60% {
    transform: scale(1.2);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}
@keyframes scale-down {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  60% {
    transform: scale(0);
    opacity: 0;
  }
}

              
            
!

JS

              
                jQuery(document).ready(function($) {

  // set animation timing
  var animationDelay = 2500,
      // loading bar effect
      barAnimationDelay = 3800,
      barWaiting = barAnimationDelay - 3000, // 3s is the duration of the transition on the loading bar - set in CSS
      // letters effect
      lettersDelay = 50;

  initHeadline();

  function initHeadline() {
    // insert <i> element for each letter of a changing word
    singleLetters($('.cd-headline.letters').find('b'));
    // initialise headline animation
    animateHeadline($('.cd-headline'));
  }

  function singleLetters($words) {
    $words.each(function() {
      var word = $(this),
          letters = word.text().split(''),
          selected = word.hasClass('is-visible');
      for (i in letters) {
        if(word.parents('.rotate-2').length > 0) letters[i] = '<em>' + letters[i] + '</em>';
        letters[i] = (selected) ? '<i class="in">' + letters[i] + '</i>': '<i>' + letters[i] + '</i>';
      }
      var newLetters = letters.join('');
      word.html(newLetters);
    });
  }

  function animateHeadline($headlines) {
    var duration = animationDelay;
    $headlines.each(function() {
      var headline = $(this);
      var spanWrapper = headline.find('.cd-words-wrapper'),
          newWidth = spanWrapper.width() + 5;
      spanWrapper.css('width', newWidth);
      if(headline.hasClass('loading-bar')) {
        duration = barAnimationDelay;
        spanWrapper.css('width', '');
        setTimeout(function(){ spanWrapper.addClass('is-loading') }, barWaiting);
      };
      //trigger animation
      setTimeout(function(){ hideWord( headline.find('.is-visible').eq(0) ) }, duration);
    });
  }

  function hideWord($word) {
    var nextWord = takeNext($word);
    if($word.parents('.cd-headline').hasClass('letters')) {
      var bool = ($word.children('i').length >= nextWord.children('i').length) ? true : false;
      hideLetter($word.find('i').eq(0), $word, bool, lettersDelay);
      showLetter(nextWord.find('i').eq(0), nextWord, bool, lettersDelay);
    } else if ($word.parents('.cd-headline').hasClass('loading-bar')) {
      $word.parents('.cd-words-wrapper').removeClass('is-loading');
      switchWord($word, nextWord);
      setTimeout(function(){ hideWord(nextWord) }, barAnimationDelay);
      setTimeout(function(){ $word.parents('.cd-words-wrapper').addClass('is-loading') }, barWaiting);
    } else {
      switchWord($word, nextWord);
      setTimeout(function(){ hideWord(nextWord) }, animationDelay);
    }
  }

  function hideLetter($letter, $word, $bool, $duration) {
    $letter.removeClass('in').addClass('out');
    if(!$letter.is(':last-child')) {
      setTimeout(function(){ hideLetter($letter.next(), $word, $bool, $duration); }, $duration);
    } else if($bool) {
      setTimeout(function(){ hideWord(takeNext($word)) }, animationDelay);
    }
    if($letter.is(':last-child') && $('html').hasClass('no-csstransitions')) {
      var nextWord = takeNext($word);
      switchWord($word, nextWord);
    }
  }

  function showLetter($letter, $word, $bool, $duration) {
    $letter.addClass('in').removeClass('out');
    if(!$letter.is(':last-child')) {
      setTimeout(function(){ showLetter($letter.next(), $word, $bool, $duration); }, $duration);
    } else {
      if(!$bool) { setTimeout(function(){ hideWord($word) }, animationDelay) }
    }
  }

  function takeNext($word) {
    return (!$word.is(':last-child')) ? $word.next() : $word.parent().children().eq(0);
  }

  function takePrev($word) {
    return (!$word.is(':first-child')) ? $word.prev() : $word.parent().children().last();
  }

  function switchWord($oldWord, $newWord) {
    $oldWord.removeClass('is-visible').addClass('is-hidden');
    $newWord.removeClass('is-hidden').addClass('is-visible');
  }

  // this is for the demo only
  var intro = $('.cd-intro');
  $('.cd-filter input').on('change', function(event){
    var selected = $(event.target).attr('id');
    switch(selected) {
      case 'rotate-1':
        intro.load('https://codepen.io/lembitk/pen/mJbxXJ.html .rotate-1', function(){
          initHeadline();
        });
        break;
      case 'rotate-2':
        intro.load('https://codepen.io/lembitk/pen/mJbxXJ.html .rotate-2', function(){
          initHeadline();
        });
        break;
      case 'loading-bar':
        intro.load('https://codepen.io/lembitk/pen/mJbxXJ.html .loading-bar', function(){
          initHeadline();
        });
        break;
      case 'slide':
        intro.load('https://codepen.io/lembitk/pen/mJbxXJ.html .slide', function(){
          initHeadline();
        });
        break;
      case 'scale':
        intro.load('https://codepen.io/lembitk/pen/mJbxXJ.html .scale', function(){
          initHeadline();
        });
        break;
    }
  });

});

              
            
!
999px

Console