cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

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.

            
              - var phrases = [
- { text: 'Hello world' },
- { text: 'Good morning', duration: 0.4, stagger: 0.1 },
- { text: 'Great days are coming', duration: 0.2, stagger: -0.05 },
- { text: 'Live for tomorrow', duration: 0.1, stagger: 0.1 },
- { text: 'Roll with the punches', stagger: -0.015},
- { text: 'Have a blast', duration: 1, stagger: 0.025 },
- { text: 'Bet on black', duration: 0.8, stagger: -0.025 },
- { text: 'Tuck and roll', duration: 0.1, stagger: -0.075 }
- ]

ul.grid
  each phrase in phrases
    li.grid__item
      h2.letter-wrap(data-duration=phrase.duration data-stagger=phrase.stagger)= phrase.text
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Source+Sans+Pro:700');

$bp-sm: 600px;
$bg-color: seagreen;

:root {
  --bg-color: #{$bg-color};
  --primary-clr: black;
  --secondary-clr: white;
  --base-ff: 'Source Sans Pro', sans-serif;
  --h2-fs: 2.25rem;
  --pad: 2rem;
}

* {
  box-sizing: border-box;
}

.grid {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  min-height: 100vh;
  font-family: var(--base-ff);
  
  &__item {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 100%;
    width: 50vw;
    height: 50vh;
    padding: var(--pad);
    background-color: var(--bg-color);
    
    @media (min-width: $bp-sm) {
      flex: 1 0 50%;
    }

    &:nth-child(even) {
      background-color: lighten($bg-color, 6%);
    }
    &:nth-child(3n) {
      background-color: darken($bg-color, 2%);
    }
    &:nth-child(4n) {
      background-color: lighten($bg-color, 8%);
    }
    &:nth-child(5n) {
      background-color: darken($bg-color, 6%);
    }
  }
}

h2 {
  font-size: var(--h2-fs);
  text-align: center;
  color: var(--primary-clr);
}

.letter-wrap {
  display: inline-block;
  position: relative;
}

.letter-wrap * {
  pointer-events: none;
}

.letter-wrap__word {
  display: inline-flex;
  position: relative;
  overflow: hidden;
}

.letter-wrap__char {
  display: inline-block;
  position: relative;
  text-transform: uppercase;
  
  &-inner {
    display: inline-block;
    
    &:after {
      content: attr(data-letter);
      position: absolute;
      top: 100%;
      left: 0;
      color: var(--secondary-clr);
    }
  }
}
            
          
!
            
              const letterWrapClass = 'letter-wrap';
const letterWrapElements = document.getElementsByClassName(letterWrapClass);

[...letterWrapElements].forEach(el => {
  letterWrap(el, letterWrapClass);
  letterAnimation(el, letterWrapClass);
});



function letterWrap(el, cls) {
  const words = el.textContent.split(' ');
  const letters = [];
  
  cls = cls || 'letter-wrap'
  
  words.forEach(word => {
    let html = '';
    for (var letter in word) {
      html += `
        <span class="${cls}__char">
          <span class="${cls}__char-inner" data-letter="${word[letter]}">
            ${word[letter]}
          </span>
        </span>
      `;
    };
    
    let wrappedWords = `<span class="${cls}__word">${html}</span>`;
    letters.push(wrappedWords);
  });
  
  return el.innerHTML = letters.join(' ');
}

function letterAnimation(el, cls) {
  const tl = new TimelineMax({ paused: true });
  const characters = el.querySelectorAll(`.${cls}__char-inner`);
  const duration = el.hasAttribute('data-duration') ? el.dataset.duration : 0.3;
  const stagger = el.hasAttribute('data-stagger') ? el.dataset.stagger : 0.03;
  
  el.animation = tl.staggerTo(characters, duration, {
    y: '-100%',
    ease: Power4.easeOut
  }, stagger);
      
  el.addEventListener('mouseenter', (event) => event.currentTarget.animation.play());
  el.addEventListener('mouseout', (event) => el.animation.reverse());
}
            
          
!
999px
Loading ..................

Console