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

Auto Save

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

              
                <div class="page">
  <div class="title__container">
    <div class="title">
      <h1>Form Field Transitions</h1>
      <p class="desc">An experiment with forms and the <a href="https://github.com/daneden/animate.css">animate.css</a> library. Select the out and in transitions in the select box below.</p>
    </div>
  </div>
  <div class="container">
    <!-- Regular Survey Style Form -->
    <form class="form__container" id="form__container">
      <div class="field">
        <p class="field__question">How likely are you to fill out this survey?</p>
        <label class="field__answer">
          <input type="radio" name="question-0" value="value-0">Extremely likely
        </label>
        <label class="field__answer">
          <input type="radio" name="question-0" value="value-1">Very likely
        </label>
        <label class="field__answer">
          <input type="radio" name="question-0" value="value-2">Moderately likely
        </label>
        <label class="field__answer">
          <input type="radio" name="question-0" value="value-3">Not so likely
        </label>
        <label class="field__answer">
          <input type="radio" name="question-0" value="value-4">Not at all likely
        </label>
      </div>
      <div class="field">
        <p class="field__question">Would you rather do something else than read this question?</p>
        <label class="field__answer">
          <input type="radio" name="question-1" value="value-0">Yes, absolutely
        </label>
        <label class="field__answer">
          <input type="radio" name="question-1" value="value-1">What? No, I love answering questions.
        </label>
      </div>
      <div class="field">
        <p class="field__question">How many times have you filled out a form like this?</p>
        <label class="field__answer">
          <input type="radio" name="question-2" value="value-0">None
        </label>
        <label class="field__answer">
          <input type="radio" name="question-2" value="value-1">1
        </label>
        <label class="field__answer">
          <input type="radio" name="question-2" value="value-2">2
        </label>
        <label class="field__answer">
          <input type="radio" name="question-2" value="value-3">3
        </label>
        <label class="field__answer">
          <input type="radio" name="question-2" value="value-4">4
        </label>
      </div>
      <div class="field">
        <p class="field__question">Do you feel like this is the last question?</p>
        <label class="field__answer">
          <input type="radio" name="question-3" value="value-0">Definitely sure
        </label>
        <label class="field__answer">
          <input type="radio" name="question-3" value="value-1">Reasonably sure
        </label>
        <label class="field__answer">
          <input type="radio" name="question-3" value="value-2">Starting to question it
        </label>
        <label class="field__answer">
          <input type="radio" name="question-3" value="value-3">I wish, but thinking not
        </label>
      </div>
      <div class="field">
        <p class="field__question">Okay click this one and you're done.</p>
        <label class="field__answer">
          <input type="radio" name="question-4" value="value-0">Really!?
        </label>
        <label class="field__answer">
          <input type="radio" name="question-4" value="value-1">Yes.
        </label>
      </div>
    </form>

    <ul id="form__progress" class="form__progress"></ul>

    <!-- Actions -->
    <div class="form__btn-row">
      <span>
      <select id="select-exits">
        <optgroup label="Sliding Exits">
          <option value="slideOutUp">slideOutUp</option>
          <option value="slideOutDown">slideOutDown</option>
          <option value="slideOutLeft">slideOutLeft</option>
          <option value="slideOutRight">slideOutRight</option>
        </optgroup>
        <optgroup label="Fading Exits">
          <option value="fadeOut">fadeOut</option>
          <option value="fadeOutDown">fadeOutDown</option>
          <option value="fadeOutDownBig">fadeOutDownBig</option>
          <option value="fadeOutLeft">fadeOutLeft</option>
          <option value="fadeOutLeftBig">fadeOutLeftBig</option>
          <option value="fadeOutRight">fadeOutRight</option>
          <option value="fadeOutRightBig">fadeOutRightBig</option>
          <option value="fadeOutUp">fadeOutUp</option>
          <option value="fadeOutUpBig">fadeOutUpBig</option>
        </optgroup>
        <optgroup label="Zoom Exits">
          <option value="zoomOut">zoomOut</option>
          <option value="zoomOutDown">zoomOutDown</option>
          <option value="zoomOutLeft">zoomOutLeft</option>
          <option value="zoomOutRight">zoomOutRight</option>
          <option value="zoomOutUp">zoomOutUp</option>
        </optgroup>
        <optgroup label="Flippers">
          <option value="flipOutX">flipOutX</option>
          <option value="flipOutY">flipOutY</option>
        </optgroup>
        <optgroup label="Lightspeed">
          <option value="lightSpeedOut">lightSpeedOut</option>
        </optgroup>
        <optgroup label="Rotating Exits">
          <option value="rotateOut">rotateOut</option>
          <option value="rotateOutDownLeft">rotateOutDownLeft</option>
          <option value="rotateOutDownRight">rotateOutDownRight</option>
          <option value="rotateOutUpLeft">rotateOutUpLeft</option>
          <option value="rotateOutUpRight">rotateOutUpRight</option>
        </optgroup>
        <optgroup label="Bouncing Exits">
          <option value="bounceOut">bounceOut</option>
          <option value="bounceOutDown">bounceOutDown</option>
          <option value="bounceOutLeft">bounceOutLeft</option>
          <option value="bounceOutRight">bounceOutRight</option>
          <option value="bounceOutUp">bounceOutUp</option>
        </optgroup>
        <optgroup label="Specials">
          <option value="rollOut">rollOut</option>
        </optgroup>
        <optgroup label="---">
          <option value="">No Exit</option>
        </optgroup>
      </select>
    </span>
      <span>
      <select id="select-entrances">
        <optgroup label="Sliding Entrances">
          <option value="slideInUp">slideInUp</option>
          <option value="slideInDown">slideInDown</option>
          <option value="slideInLeft">slideInLeft</option>
          <option value="slideInRight">slideInRight</option>
        </optgroup>
        <optgroup label="Fading Entrances">
          <option value="fadeIn">fadeIn</option>
          <option value="fadeInDown">fadeInDown</option>
          <option value="fadeInDownBig">fadeInDownBig</option>
          <option value="fadeInLeft">fadeInLeft</option>
          <option value="fadeInLeftBig">fadeInLeftBig</option>
          <option value="fadeInRight">fadeInRight</option>
          <option value="fadeInRightBig">fadeInRightBig</option>
          <option value="fadeInUp">fadeInUp</option>
          <option value="fadeInUpBig">fadeInUpBig</option>
        </optgroup>
        <optgroup label="Zoom Entrances">
          <option value="zoomIn">zoomIn</option>
          <option value="zoomInDown">zoomInDown</option>
          <option value="zoomInLeft">zoomInLeft</option>
          <option value="zoomInRight">zoomInRight</option>
          <option value="zoomInUp">zoomInUp</option>
        </optgroup>
        <optgroup label="Flippers">
          <option value="flipInX">flipInX</option>
          <option value="flipInY">flipInY</option>
        </optgroup>
        <optgroup label="Lightspeed">
          <option value="lightSpeedIn">lightSpeedIn</option>
        </optgroup>
        <optgroup label="Rotating Entrances">
          <option value="rotateIn">rotateIn</option>
          <option value="rotateInDownLeft">rotateInDownLeft</option>
          <option value="rotateInDownRight">rotateInDownRight</option>
          <option value="rotateInUpLeft">rotateInUpLeft</option>
          <option value="rotateInUpRight">rotateInUpRight</option>
        </optgroup>
        <optgroup label="Bouncing Entrances">
          <option value="bounceIn">bounceIn</option>
          <option value="bounceInDown">bounceInDown</option>
          <option value="bounceInLeft">bounceInLeft</option>
          <option value="bounceInRight">bounceInRight</option>
          <option value="bounceInUp">bounceInUp</option>
        </optgroup>
        <optgroup label="Specials">
          <option value="rollIn">rollIn</option>
        </optgroup>
      </select>
    </span>
      <span><a href="#" id="lucky">lucky</a></span>
    </div>
  </div>

</div>
              
            
!

CSS

              
                $primary: #e7e7e7;
$secondary: #E80C7A;

* {
  box-sizing: border-box;
}

html {
  color: #222;
  text-rendering: optimizeLegibility;
  padding: 1em;
  background: lighten($primary, 8%);
}

a {
  color: #222;
}

h1 {
  font-family: 'Bitter', serif;
  text-align: center;
  font-size: 1.5em;
  color: $secondary;
}

label {
  display: block;
  user-select: none;
  cursor: pointer;
  line-height: 2.5;
  font-family: 'Oswalt', sans-serif;
  font-weight: 300;
  transition: padding-left 200ms ease-in;
  &:hover {
    color: #000;
    padding-left: 4px;
    font-weight: 400;
  }
}

input {
  margin-right: .5em;
}

.container {
  margin: 0 auto;
  max-width: 600px;
}

.field, .form__container {
  width: 100%;
}

.form__container {
  margin: 1em auto;
  background: #fff;
  border: 8px solid $primary;
  perspective: 1200;
  position: relative;
  min-height: 300px;
  overflow: hidden;
  transition: all 300ms linear;
  &:hover {
    border-color: darken($primary, 3%);
  }
}

.field {
  padding: 2em 3em;
  position: absolute;
  visibility: hidden;
  overflow: hidden;
  backface-visibility: hidden;
  transform: translate3d(0, 0, 0);
  transform-style: preserve-3d;
}

.is-current {
  visibility: visible;
  z-index: 1;
}

.form__btn-row {
  margin: 4em auto;
}

.form__btn-row span {
  width: 32%;
  text-align: center;
  display: inline-block;
  padding: 0;
  margin: 0;
}

p.desc {
  margin-bottom: 3em;
  text-align: center;
  /* color: #777; */
  font-size: 0.9em;
  font-family: 'Oswalt', sans-serif;
  font-weight: 300;
  a {
    color: $secondary;
    text-decoration: none;
  }
}

.field__question {
  font-size: 1.2em;
  border-bottom: 3px solid $primary;
  padding: 0 2em 1em 0;
  margin-top: 0;
  position: relative;
  font-family: 'Bitter', serif;
  line-height: 1.4;
  &:after {
    content: '*';
    position: absolute;
    right: 0;
    top: -3px;
    color: #e7e7e7;
    font-size: 2em;
  }
}

.form__progress {
  list-style-type: none;
  text-align: center;
  li {
    background: #fff;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    margin: 0 5px;
    display: inline-block;
    border: 3px solid darken($primary, 0%);
    transition: background 200ms linear;
    &.is-current {
      background: linear-gradient(left, #fff 50%, $primary 50%);
      & ~ li {
        background: $primary;
      }
    }
  }
}
              
            
!

JS

              
                (function($, Modernizr) {

      // Default State
  var isAnimating     = false,
      animateInClass  = $('#select-entrances').val(),
      animateOutClass = $('#select-exits').val(),

      // Cache Selectors
      $container      = $('#form__container'),
      $progress       = $('#form__progress'),
      $select         = $('select'),
      $entrances      = $('#select-entrances'),
      $exits 				  = $('#select-exits'),
      $lucky          = $('#lucky'),

      // Browsers emit custom event on css animation end
      animateEndEvent = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';

  /**
   * Reset all animation State
   * @param {obj} $current exiting field obj
   * @param {obj} $next    entering field obj
   */
  function resetAnimation($current, $next) {
    isAnimating = false;
    $current.removeClass('is-current animated ' + animateOutClass);
    $next.removeClass(animateInClass);
  }

  /**
   * Run animation
   * @param {obj} $current exiting field obj
   * @param {obj} $next    entering field obj
   */
  function startAnimation($current, $next) {
    if (isAnimating || !Modernizr.cssanimations) { return; }

    // set flag to debounce multiple clicks
    isAnimating = true;

    // begin animating out field
    $current.addClass(animateOutClass);

    // begin animating in field
    $next
      .addClass(animateInClass)
      .one(animateEndEvent, function() {
        resetAnimation($current, $next);
      });
  }

  /**
   * Helper action to click first input on field
   */
  function clickField() {
    $('.field.is-current').find('input:first').click();
  }

  /**
   * Helper action to set height of container
   * @param {number} height set container value
   */
  function setContainerHeight(height) {
    $container.height(height);
  }

  /**
   * 
   * Fade out all labeles except selected
   * @param {object} el current label being clicked
   */
  function fadeLabels(el) {
    var $siblings = $(el).siblings('label');
    return $siblings
            .addClass('animated fadeOut')
            .one(animateEndEvent, function() {
              setTimeout(function() {
                $siblings.removeClass('fadeOut');
              }, 1000);
            });
  }


  /**
   * Start animation process
   */
  function handleClick(e) {
    if (isAnimating) { return; }
    var $this = $(this).parent('.field');
    var $next = $this.is(':last-child') ? $this.parent().children(':first') : $this.next();

    // Set container height to height of next field
    setContainerHeight($next.outerHeight());
    
    // Update progress dots
    setProgressDot($next);
    
    // Fade all labels except selected
    fadeLabels(e.target);

    // let user feel like selection was made, then start animation
    setTimeout(function() {
      $next.addClass('is-current animated');
      startAnimation($this, $next);
    }, 200);

    setTimeout(function() {
      $('input').prop('checked', false);
    }, 1000);
  }

  /**
   * set anim classes and click form
   */
  function handleSelect() {
    animateInClass = $entrances.val();
    animateOutClass = $exits.val();
    clickField();
  }

  /**
   * Randomize select dropdowns
   * @param {obj} e jquery event obj
   */
  function handleLucky(e) {
    e.preventDefault();
    if (isAnimating) { return; }

    $select.each(function(i, obj) {
      var $obj = $(obj);
      var $options = $obj.find('option');
      var rand = Math.floor(Math.random() * $options.length);
      $obj.val($options.eq(rand).val());
    });

    handleSelect();
  }

  /**
   * Create progress list based on length of questions
   */
  function setupProgress() {
    var val = $('.field').length;
    var i = 0;
  	while (i < val) {
      $progress.append('<li/>');
      i++;
    }
    setProgressDot();
  }

  /**
   * Update progress dot to current question
   * @param {object} $el $ object representing next question
   */
  function setProgressDot($el) {
  	$progress.find('li')
     .removeClass('is-current')
     .eq($el ? $('.field').index($el) : 0)
     .addClass('is-current');
  }

  /**
   * Setup all listeners on page
   */
  function setupListeners() {
    $container.on('click', 'label', handleClick);
    $select.on('change', handleSelect);
    $lucky.on('click', handleLucky);
  }


  function init() {

    // Setup first field
    var $firstField = $container.children(':first');
    $firstField.addClass('is-current animated');
    setContainerHeight($firstField.outerHeight());

    // setup progress bar
    setupProgress();

    // Add listeners to page
    setupListeners();

  }

  init();

}(window.jQuery, window.Modernizr));

              
            
!
999px

Console