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

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

              
                <form id="credit-card-form">
  
  <svg id="checkmark" data-name="checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 44.39 44.39">
    <title>checkmark</title>
    <circle id="circle" cx="22.19" cy="22.19" r="21.19" style="fill: none;stroke: #37cc89;stroke-miterlimit: 10;stroke-width: 2px"/>
    <line id="check1" x1="10.78" y1="23" x2="18.32" y2="30.54" style="fill: none;stroke: #37cc89;stroke-miterlimit: 10;stroke-width: 2px"/>
    <line id="check2" x1="17.3" y1="30.16" x2="33.61" y2="13.85" style="fill: none;stroke: #37cc89;stroke-miterlimit: 10;stroke-width: 2px"/>
  </svg>
  
  <div id="credit-card" class="credit-card">
    <div class="credit-card__wrap">
      <div class="credit-card__face credit-card--front">
        <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/268015/visa.png" alt="visa" class="visa-logo" id="card-logo">
        <div class="input-wrap input-wrap--number">
          <input id="first-number" class="credit-card__number card-front" type="text" placeholder="XXXX" maxlength="4" required><!--
       --><input class="credit-card__number card-front" type="text" placeholder="XXXX" maxlength="4" required><!--
       --><input class="credit-card__number card-front" type="text" placeholder="XXXX" maxlength="4" required><!--
       --><input id="last-number" class="credit-card__number card-front" type="text" placeholder="XXXX" maxlength="4" required>
        </div>
        <div class="input-wrap input-wrap--expiration">
          <p class="input-wrap--expiration-text">Good<br>Thru</p>
          <input id="first-exp" class="credit-card__month card-front" type="text" placeholder="01" maxlength="2" required>
          <input id="last-exp" class="credit-card__year card-front" type="text" placeholder="18" maxlength="2" required>
        </div>
        <div class="input-wrap input-wrap--name">
          <input class="credit-card__first card-front" type="text" placeholder="First" maxlength="40" required>
          <input class="credit-card__last card-front" type="text" placeholder="Last" maxlength="80" required>
        </div>
      </div>
      <div class="credit-card__face credit-card--back">
        <div class="credit-card__strip"></div>
        <div class="credit-card__signature"></div>
        <input class="credit-card__cvv card-back" type="text" placeholder="cvv" maxlength="4" required tabindex="-1">
      </div>
    </div>
  </div>
  <button id="cc-submit-btn" class="credit-card__submit"><span id="inner-text">Next</span><span id="sign-up-loader" class="credit-card__loader"></span></button>
</form>
              
            
!

CSS

              
                // Colors
$blue: #377bcc;
$green: #37cc89;
$grey: #bbb;
$red: #cc4b37;
$white: #f9f9f9;

html {
  font-size: 8px;
  @media only screen and (min-width: 400px) {
    font-size: 10px;
  }
  @media only screen and (min-width: 1700px) {
    font-size: 12px;
  }
}

body {
  background-color: $white;
  font-family: "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
}

#checkmark {
  max-width: 100px;
  position: absolute;
  top: 47%;
  left: 50%;
  transform: translate(-50%, -50%);
  visibility: hidden;
  opacity: 0;
}

// Ripple effect
.ink {
  display: block;
  position: absolute;
  background:rgba(255, 255, 255, 0.3);
  border-radius: 100%;
  transform:scale(0);
}

.animate {
  animation:ripple 0.65s linear;
}

@keyframes ripple {
  100% {opacity: 0; transform: scale(2.5);}
}

.visa-logo {
  color: $white;
  float: right;
  margin: 1.8rem 2.4rem 0 0;
  width: 6rem;
}

#credit-card-form {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.credit-card {
  height: 23rem;
  width: 37rem;
  text-transform: uppercase;
  visibility: hidden;
  opacity: 0;
  &__strip {
    background-color: #000;
    width: 100%;
    height: 3rem;
    position: relative;
    top: 2rem;
  }
  &__signature {
    height: 3rem;
    width: 55.5%;
    background-color: $white;
    position: relative;
    top: 6rem;
    margin-left: 2.4rem;
    display: inline-block;
  }
  &__cvv {
    height: 3rem;
    display: inline-block;
    width: 25%;
    margin-left: 2rem;
    position: relative;
    top: 6rem;
    vertical-align: top;
    padding: 0.5rem 0 0.5rem 3.3rem;
  }
  &__wrap {
    position: relative;
    transform-style: preserve-3d;
    transition: 0.6s;
  }
  &__wrap.flipped {
   transform: rotateY(-180deg);
  }
  &__face {
    height: 23rem;
    width: 37rem;
    background-color: $blue;
    border-radius: 1rem;
    position: absolute;
    top: 0;
    left: 0;
    backface-visibility: hidden;
    box-shadow: 2px 2px 1px rgba(0,0,0,0.1);
  }
  &--front {
    transform: rotateY(0deg);
  }
  &--back {
    transform: rotateY(-180deg);
  }
  &__number {
    width: 7rem;
    letter-spacing: 0.2rem;
    padding: 0.5rem 0 0.5rem 1.1rem;
    margin-left: 1.4rem;
    &:first-child {
      margin-left: 0;
    }
  }
  &__month {
    width: 4rem;
    letter-spacing: 0.2rem;
    padding: 0.3rem 0 0.3rem 1rem;
    margin-right: 0.5rem;
  }
  &__year {
    width: 4rem;
    letter-spacing: 0.2rem;
    padding: 0.3rem 0 0.3rem 1rem;
    margin-right: 2.4rem;
  }
  &__first {
    width: 12rem;
    letter-spacing: 0.1rem;
    padding: 0.3rem 0 0.3rem 1rem;
    margin-left: 2.4rem;
    margin-right: 1rem;
  }
  &__last {
    width: 19rem;
    letter-spacing: 0.1rem;
    padding: 0.4rem 0 0.4rem 1rem;
  }
  input[type="text"] {
    background-color: lighten($blue, 6%);
    border: none;
    color: $white;
    font-family: 'Roboto Mono', 'Courier New', Courier, 'Lucida Sans Typewriter', 'Lucida Typewriter', monospace;
    &::-webkit-input-placeholder {
      color: $white;
    }
    &:-moz-placeholder {
      color: $white;
    }
    &::-moz-placeholder {
      color: $white;
    }
    &:-ms-input-placeholder {  
      color: $white;
    }
  }
  &__submit {
    background-color: darken($grey, 5%);
    border: none;
    padding: 1rem 0;
    width: 37rem;
    color: $white;
    font-size: 1.8rem;
    transform: translateZ(0);
    box-shadow: 2px 2px 1px rgba(0,0,0,0.1);
    overflow: hidden;
    transition: background-color 0.3s ease-in-out;
    outline: 0;
    margin-top: 2.4rem;
    position: relative;
    visibility: hidden;
    opacity: 0;
    &:focus, &:hover {
      background-color: $grey;
    }
  }
  &__loader {
    display: block;
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    background-color: $blue;
    height: 4px;
  }
}

.input-wrap {
  &--number {
    position: absolute;
    top: 7.8rem;
    font-size: 1.8rem;
    width: 100%;
    text-align: center;
  }
  &--name {
    position: absolute;
    bottom: 2.4rem;
    font-size: 1.6rem;
    width: 100%;
  }
  &--expiration {
    position: absolute;
    bottom: 6.8rem;
    text-align: right;
    font-size: 1.6rem;
    width: 100%;
    &-text {
      display: inline-block;
      position: relative;
      top: 0.2rem;
      line-height: 1;
      color: $white;
      font-size: 0.8rem;
      text-align: right;
      margin-right: 0.5rem;
      letter-spacing: 0.1rem;
    }
  }
}
              
            
!

JS

              
                $form      = $('#credit-card-form');
$card      = $form.find('#credit-card');
$btn       = $form.find('#cc-submit-btn');
$loader    = $form.find('.credit-card__loader');
$firstNum  = $form.find('#first-number');
$lastNum   = $form.find('#last-number');
$firstExp  = $form.find('#first-exp');
$lastExp   = $('#last-exp');
$logo      = $form.find('#card-logo');
$cardNum   = $form.find('.credit-card__number');
$cardMonth = $form.find('.credit-card__month');
$submitBtn = $form.find('#cc-submit-btn');
$cvv       = $form.find('.credit-card__cvv');
$cardWrap  = $form.find('.credit-card__wrap');
$cardFront = $form.find('.card-front');
$firstName = $form.find('.credit-card__first');

var clickCount = 0;
var formHeight = $form.outerHeight();
var btnHeight  = $btn.outerHeight();
var diff       = (formHeight / 2) - (btnHeight / 2);

var tl = new TimelineMax();

var showCheck = function() {
  tl.set('#checkmark', {autoAlpha: 1})
    .fromTo('#circle', 0.6, {drawSVG: '0%'}, {drawSVG: '100%', ease: Power3.easeInOut})
    .fromTo('#check1', 0.3, {drawSVG: '0%'}, {drawSVG: '100%', ease: Power3.easeInOut}, '-=0.1')
    .fromTo('#check2', 0.3, {drawSVG: '0%'}, {drawSVG: '100%', ease: Power3.easeInOut}, '-=0.2');
};

var hideForm = function() {
  TweenMax.to($btn, 0.3, {scale: 0.3, autoAlpha: 0, ease: Back.easeInOut, onComplete: showCheck});
};

function submitCard() {
  TweenMax.to($card, 0.5, {y: -20, autoAlpha: 0, ease: Back.easeInOut});
  TweenMax.to($btn, 1, {y: diff * -1, delay: 0.1, ease: Back.easeInOut});
  $btn.find('#inner-text').text('Processing...');
  TweenMax.to($loader, 1.5, {width: '100%', ease: Power0.easeNone, onComplete: hideForm});
}

// Fade in up
TweenMax.fromTo($card, 0.5, {y: 20, autoAlpha: 0}, {y: 0, autoAlpha: 1, delay: 0.5});
TweenMax.fromTo($btn, 0.5, {y: 20, autoAlpha: 0}, {y: 0, autoAlpha: 1, delay: 0.6});

$firstNum.focus();

// Only allow numbers in number fields
$('.credit-card__number, .credit-card__month, .credit-card__year, .credit-card__cvv').keydown(function(e) {
  // Allow: backspace, delete, tab, escape, enter and .
  if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
    // Allow: Ctrl+A
    (e.keyCode == 65 && e.ctrlKey === true) ||
    // Allow: Ctrl+C
    (e.keyCode == 67 && e.ctrlKey === true) ||
    // Allow: Ctrl+X
    (e.keyCode == 88 && e.ctrlKey === true) ||
    // Allow: home, end, left, right
    (e.keyCode >= 35 && e.keyCode <= 39)) {
    // let it happen, don't do anything
    return;
  }
  // Ensure that it is a number and stop the keypress
  if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
    e.preventDefault();
  }
});

// Change cc logo
$firstNum.keyup(function(){
  var visa = /^4/g;
  var amex = /^3/g;
  var mc = /^5/g;
  var discover = /^6/g;
  if (visa.test($(this).val())) {
    $logo.attr({
      src: 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/268015/visa.png',
      alt: 'visa'
    });
  } else if (amex.test($(this).val())) {
    $logo.attr({
      src: 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/268015/amex.png',
      alt: 'amex'
    });
  } else if (mc.test($(this).val())) {
    $logo.attr({
      src: 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/268015/mc.png',
      alt: 'mastercard'
    });
  } else if (discover.test($(this).val())) {
    $logo.attr({
      src: 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/268015/discover.png',
      alt: 'discover'
    });
  }
});

// Go to next cc number
$cardNum.keyup(function(){
  if ($(this).val().length === 4) {
    $(this).next().focus();
  }
});
// Go to first exp number
$lastNum.keyup(function(){
  if ($(this).val().length === 4) {
    $firstExp.focus();
  }
});
// Go to next exp number
$cardMonth.keyup(function(){
  if ($(this).val().length === 2) {
    $(this).next().focus();
  }
});
// Go to first name
$lastExp.keyup(function(){
  if ($(this).val().length === 2) {
    $firstName.focus();
  }
});

$submitBtn.click(function(e){
  e.preventDefault();
  
  // Ripple effect
  if ($(this).find(".ink").length === 0) {
    $(this).prepend("<span class='ink'></span>");
  }

  ink = $(this).find(".ink");
  ink.removeClass("animate");

  if (!ink.height() && !ink.width()) {
    d = Math.max($(this).outerWidth(), $(this).outerHeight());
    ink.css({height: d, width: d});
  }

  x = e.pageX - $(this).offset().left - ink.width()/2;
  y = e.pageY - $(this).offset().top - ink.height()/2;

  ink.css({top: y+'px', left: x+'px'}).addClass("animate");
  
  // Functionality
  if (clickCount === 0) {
    // validate front
    $cvv.focus().attr('tabindex', '0');
    $cardFront.attr('tabindex', '-1');
    $cardWrap.addClass('flipped');
    clickCount++;
  } else if (clickCount === 1) {
    // validate back
    $cvv.blur().attr('tabindex', '-1');
    $cardFront.attr('tabindex', '0');
    $cardWrap.removeClass('flipped');
    $(this).find('#inner-text').text('Submit');
    $(this).css('background-color', '#37cc89');
    clickCount++;
  } else if (clickCount === 2) {
    submitCard();
  }
});
              
            
!
999px

Console