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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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 btnText1 = 'Submit'
- var btnText2 = 'Share this page'
- var btnText3 = 'Looking good, Billy Ray!'
- var btnText4 = 'Feeling good, Louis!'
- var btnText5 = 'Now go backwards'

h1 Lettering.js Button Hover States
main
  button.btn.btn--action.btn--one()= btnText1
  button.btn.btn--action.btn--two(data-duration="0.4" data-stagger="0.018")= btnText2
  button.btn.btn--action.btn--three(data-duration="0.2" data-stagger="0.014")= btnText3
  button.btn.btn--action.btn--four(data-duration="0.8" data-stagger="0.04")= btnText4
  button.btn.btn--action.btn--five(data-duration="0.3" data-stagger="-0.014")= btnText5
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Lato:400,700');

$black: black;
$blue: lightblue;
$gray: lightslategray;
$green: darkseagreen;
$red: crimson;
$tan: tan;
$white: white;

$base--font-family: 'Lato', Arial, sans-serif;
$base--trans-speed: 0.4s;
$base--trans-timefunc: cubic-bezier(0.645, 0.045, 0.355, 1);

@function em($pixels, $context: 16) {
  @return #{$pixels/$context}em;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: em(12);
  min-height: 100vh;
}

main {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

h1 {
  margin-bottom: em(24);
  font-family: $base--font-family;
  font-size: em(30);
  line-height: 1.2;
  font-weight: 700;
}

// Buttons
.btn {
  $btn--padding: em(12) em(24);
  $btn--margin: em(6);
  $btn--offset: 4px;
  $btn--trans: $base--trans-speed $base--trans-timefunc;
  
  display: inline-block;
  position: relative;
  cursor: pointer;
  overflow: hidden;
  margin: $btn--margin;
  padding: $btn--padding;
  font-size: em(18);
  font-family: $base--font-family;
  text-transform: uppercase;
  letter-spacing: em(0.05);
  border: none;
  border-radius: em(2);
  transition:
    background-color $btn--trans,
    border-color $btn--trans,
    box-shadow $btn--trans,
    transform $btn--trans;
  
  &:before {
    content: '';
    position: absolute;
    bottom: 0; left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    transform: translateY(100%);
    transition: transform $btn--trans;
  }
  
  &:hover,
  &:focus {
    transform: translateY(-$btn--offset);
    box-shadow: rgba(black, 0.4) 0 em(6) em(24) em(-6);
    
    &:before {
      transform: translateY(0);
    }
  }
  
  &:active {
    transform: translateY(-$btn--offset + 1px);
    transition: transform 0s;
  }
  
  &--action [class^="word"] {
    display: inline-block;
  }
  
  &--action [class^="char"] {
    display: inline-block;
    position: relative;
    overflow: hidden;
    z-index: 2;
    
    &.letter-space {
      width: em(4);
    }
    
    span {
      display: inline-block;
    }
      
    span:before {
      content: attr(data-letter);
      display: block;
      position: absolute;
      top: 110%;
      z-index: 3;
    }
  }
}

// Button configurations
// (bg color, hover bg color, text color, hover text color)
$btn-config: (
  one: ($blue, darken($blue, 10%), $black, $white),
  two: ($green, darken($green, 10%), $black, $white),
  three: ($red, lighten($red, 10%), $white, $black),
  four: ($gray, lighten($gray, 10%), $white, $black),
  five: ($tan, darken($tan, 10%), $black, $white)
);

@each $name, $option in $btn-config {
  $btn--bg-color: nth($option, 1);
  $btn--bg-color--hover: nth($option, 2);
  $btn--txt-color: nth($option, 3);
  $btn--txt-color--hover: nth($option, 4);
  
  .btn--#{$name} {
    color: $btn--txt-color;
    background-color: $btn--bg-color;
    
    &:before {
      background-color: $btn--bg-color--hover;
      background: linear-gradient(to top, $btn--bg-color--hover, transparent);
    }

    &:hover,
    &:focus {
      outline-color: $btn--bg-color;
    }
    
    span:before {
      color: $btn--txt-color--hover;
    }
  }
}
            
          
!
            
              var $body = $('body');
var $btnAction = $('.btn--action');
var innerWrapClass = 'inner-wrap';
var $letter, $letterWrapper, $innerWrapper;

// Wrap words
$btnAction.lettering('words');

// Wrap letters
$('[class^="word"]').lettering();
$letter = $btnAction.find('[class^="char"]');

// Wrap inner to hide overflow on each letter
$letter.each(function() {
  $(this).wrapInner('<span>');
  $letterWrapper = $(this).find('span');
  
  $letterWrapper
    .addClass(innerWrapClass)
    .attr('data-letter', $(this).text());
  
  // Add class to text spaces
  if ($letterWrapper.data('letter') === ' ') {
    $(this).addClass('letter-space');
  }
});

// Setup animation
$btnAction.each(function(index, el) {
  var tl, duration, stagger, anim;
  
  $innerWrapper = $(el).find('.' + innerWrapClass);
  tl = new TimelineMax({paused: true});
  duration = $(el).attr('data-duration') ? $(el).data('duration') : 0.3;
  stagger = $(el).attr('data-stagger') ? $(el).data('stagger') : 0.03;
  
  anim = tl.staggerTo($innerWrapper, duration, {
    y: '-110%',
    ease: Back.easeOut
  }, stagger);
  
  el.animation = anim;
  
  // Apply animation to hover and focus states
  $(el).on("mouseenter focusin", function() {
    this.animation.play();
  }).on("mouseleave focusout", function() {
    this.animation.reverse();
  });
  
});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console