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 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.

            
              - 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
$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
Loading ..................

Console