Pen Settings

HTML

CSS

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

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

              
                <a href="https://youtu.be/hJY7IGnJ7AI" target="_blank" data-keyframers-credit style="color: #000"></a>
<script src="https://codepen.io/shshaw/pen/QmZYMG.js"></script>

<div id="app" data-state="step-1">
  <form class="ui-form">
    
    <ul class="ui-steps">
      <li class="ui-step" data-show="step-1"><span>1</span></li>
      <li class="ui-step" data-show="step-2"><span>2</span></li>
      <li class="ui-step" data-show="step-3"><span>3</span></li>
      <li class="ui-step" data-show="step-4"><span>4</span></li>
      <li class="ui-step" data-show="step-5"><span>5</span></li>
    </ul>
    
    <section class="ui-section" data-show="step-1">
      <div class="ui-subheading">Step 1</div>
      <h2 class="ui-heading">Welcome! How many pets are in your house right now?</h2>
      <p class="ui-paragraph">Lorem ipsum dolor sit amet consectetur adipisicing elit. Quidem ipsa aliquid adipisci! Tempore eos maxime debitis libero saepe, sunt dicta natus! Repellendus eum assumenda facere amet quo. Laborum, quibusdam ex.</p>
      <div class="ui-field">        
        <input type="number" class="ui-input" required>
        <button type="button" class="ui-button">Next</button>
      </div>
    </section>
    <section class="ui-section" data-show="step-2">
      <div class="ui-subheading">Step 1</div>
      <h2 class="ui-heading">Enter five numbers.</h2>
      <p class="ui-paragraph">Lorem ipsum dolor sit amet consectetur adipisicing elit. Quidem ipsa aliquid adipisci! Tempore eos maxime debitis libero saepe, sunt dicta natus! Repellendus eum assumenda facere amet quo. Laborum, quibusdam ex.</p>
      <div class="ui-field">        
        <input type="text" class="ui-input" pattern="\d{5}" required>
        <button type="button" class="ui-button">Next</button>
      </div>
    </section>
    <section class="ui-section" data-show="step-3">
      <div class="ui-subheading" data-flip-key="subheading-3">Step 3</div>
      <h2 class="ui-heading" data-flip-key="heading-3">Do you you need animation help?</h2>
      <p class="ui-paragraph" data-flip-key="p-3">We all need animation help, so go ahead and check that checkbox.</p>
      <label class="ui-label -choice" data-flip-key="label-3">
        <input type="checkbox" id="animation-help">
        <span class="ui-text">I need animation help</span>
      </label>
      <button type="button" class="ui-button" data-flip-key="next-3" id="step-3-button">Next</button>
    </section>
    <section class="ui-section" data-show="step-4">
      <div class="ui-subheading">Step 4</div>
      <h2 class="ui-heading">What do you think your household income would be if you were a musician?</h2>
      <p class="ui-paragraph">Lorem ipsum dolor sit amet consectetur adipisicing elit. Quidem ipsa aliquid adipisci! Tempore eos maxime debitis libero saepe, sunt dicta natus! Repellendus eum assumenda facere amet quo. Laborum, quibusdam ex.</p>
      <input type="number" class="ui-input" required>
      <button type="button" class="ui-button">Next</button>
    </section>
    <section class="ui-section" data-show="step-5">
      <div class="ui-subheading">Step 5</div>
      <h2 class="ui-heading">Choose the type of insurance.</h2>
      <p class="ui-paragraph">Lorem ipsum dolor sit amet consectetur adipisicing elit. Quidem ipsa aliquid adipisci! Tempore eos maxime debitis libero saepe, sunt dicta natus! Repellendus eum assumenda facere amet quo. Laborum, quibusdam ex.</p>
      <div class="ui-choices">
        <input type="radio" name="choice" id="choice-1" class="ui-input">
        <label for="choice-1" class="ui-choice">
          <span class="ui-text">Jank</span>
        </label>
        <input type="radio" name="choice" id="choice-2" class="ui-input">
        <label for="choice-2" class="ui-choice">
          <span class="ui-text">3D</span>
        </label>
        <input type="radio" name="choice" id="choice-3" class="ui-input">
        <label for="choice-3" class="ui-choice">
          <span class="ui-text">Physics</span>
        </label>
      </div>
      <button type="button" class="ui-button -submit" id="submit">Submit</button>
    </section>
    
    <div class="ui-section" data-show="finished">
      You're done!
    </div>
  </form>
</div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Raleway');

$color-primary: #3187F2;
$easing: cubic-bezier(.5, 0, .5, 1);

*, *:before, *:after {
  box-sizing: border-box;
  position: relative;
  transition: transform .3s $easing;
  transition-property: transform, opacity;
}

html, body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  font-family: Raleway, Helvetica, Arial, sans-serif;
}

#app {
  color: #656565;
  animation: fade-in .4s linear .3s both;
  @keyframes fade-in {
    from { opacity: 0; }
  }
}

/* ---------------------------------- */

.ui-form {
  padding: 5%;
  display: grid;
  height: 100vh;
  grid-template-columns: auto 1fr;
  grid-template-rows: 1fr;
  // align-items: center;
  justify-items: center;
}

.ui-section {
  grid-row: 1;
  grid-column: 2;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  max-width: 30em;
}

.ui-subheading {
  color: #CCC;
  font-weight: bold;
  letter-spacing: 1px;
}

.ui-input {
  appearance: none;
  border: 1px solid #CCC;
  border-radius: 2px;
  padding: .5rem;
  transition: border-color .3s ease;

  &:focus {
    outline: none;
    border-color: #3187F2;
  }
}

.ui-button {
  appearance: none;
  background: $color-primary;
  border: none;
  border-radius: 2px;
  padding: 1rem;
  display: inline-block;
  color: white;
  text-transform: uppercase;
  font-size: .75rem;
  letter-spacing: 2px;
  width: auto;
  margin-top: 1rem;
  transition-timing-function: cubic-bezier(.8, 0, .2, 1);
}

.ui-heading {
  margin: 1rem 0;
}

.ui-field {
  display: flex;
  flex-direction: row;

  > * {
    margin: 0;
  }

  > .ui-button {
    margin-left: -1rem;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    opacity: 0;
    transform: translateX(-50%);
    transition-duration: .6s;
    pointer-events: none;
  }

  > .ui-input:valid + .ui-button {
    pointer-events: auto;
    opacity: 1;
    transform: none;
  }
}

.ui-label {
  margin: 1rem 0;
}

.ui-paragraph {
  line-height: 1.5;
}

.ui-button#step-3-button {
  
  &:not([data-clickable]) {
    display: none;
  }
  
  animation: step-3-button .3s cubic-bezier(.5, 0, .5, 1);
  
  @keyframes step-3-button {
    from {
      opacity: 0;
      transform: translateY(100%);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }
}

.ui-choices {
  > input {
    opacity: 0;
    height: 1px;
    width: 1px;
    display: none;
  }
  
  > input:checked + .ui-choice {
    background: $color-primary;
    color: white;
  }
}

.ui-choice {
  transition: all .3s $easing;
  border: 2px solid $color-primary;
  display: inline-block;
  padding: 1rem;
  margin-right: 1rem;
  border-radius: 2px;
}

/* ---------------------------------- */

.ui-steps,
.ui-step {
  margin: 0;
  padding: 0;
  list-style-type: none;
}

.ui-steps {
  grid-column: 1;
  margin-right: 2rem;
  display: grid;
  place-items: center;
}

.ui-step {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
  --speed: .3s;
  --color: #{$color-primary};
  --secondary: #AAA;

  span {
    width: 2em;
    height: 2em;
    border-radius: 50%;
    background: var(--color);
    color: #FFF;
    display: grid;
    place-items: center;
    line-height: 1;
    transition: background-color var(--speed) cubic-bezier(.5, 0, .5, 1) var(--speed);
    
    &::before {
      content: '';
      position: absolute;
      top: 0; right: 0; bottom: 0; left: 0;
      width: 130%;
      height: 130%;
      margin: -15%;
      border: solid 2px var(--color);
      border-radius: 50%;
      transform: scale(0.6);
      transition: inherit;
      transition-property: transform, border-color;
    }
  }

  &::before,
  &::after {
    content: '';
    display: block;
    border-right: solid 3px var(--secondary);
    height: 100%;
    grid-row: 2;
    grid-column: 1;
    width: 0px;
    margin: 0 auto;
    transform-origin: top center;
  }

  &::after {
    transform: scaleY(1);
    border-right-color: var(--color);
    transition: transform var(--speed) cubic-bezier(.5, 0, .5, 1);
  }

  &:last-child::before,
  &:last-child::after {
    display: none; 
  }

  &[data-active] {
    span { 
      background: $color-primary; 
      
      &::before {
        transform: scale(1);
      }
    }

    &::after {
      transform: scaleY(0.5);
      transition-delay: var(--speed);
    }

    ~ .ui-step {
      --color: #AAA;
      &::after {
        transform: scaleY(0);
      }
    }
  }
}

/* ---------------------------------- */

.ui-section {
  opacity: 0;
  visibility: hidden;
  transform: translateY(-30vh);
  transition: 
    opacity .5s linear, 
    transform .5s cubic-bezier(.5, 0, .5, 1),
    visibility 0s linear .5s;
}

.ui-section[data-active] {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition-delay: 0s;
  
  ~ .ui-section {
    transform: translateY(30vh); 
  }
  
  > * {
    animation: slide-up .35s cubic-bezier(.5, 0, .5, 1) both;
    
    @for $i from 1 through 5 {
      &:nth-child(#{$i}):not(#step-3-button) {
        animation-delay: $i * 100ms !important;
      }
    }

    @keyframes slide-up {
      from {
        opacity: 0;
        transform: translateY(1rem);
      } 
      to {
        transform: none;
      }
    }
  }
}


              
            
!

JS

              
                console.clear();

const elApp = document.querySelector('#app');
const elNextButtons = Array.from(document.querySelectorAll('button:not(#submit)'));
const elSubmitButton = document.querySelector('#submit');
const elAnimationHelp = document.querySelector('#animation-help');
const elStep3Button = document.querySelector('#step-3-button');

const flipping = new Flipping();

const { Machine } = xstate;

const insuranceMachine = Machine({
  initial: elApp.dataset.state || 'step-1',
  states: {
    'step-1': {
      on: {
        NEXT: 'step-2'
      }
    },
    'step-2': {
      on: {
        NEXT: 'step-3'
      }
    },
    'step-3': {
      on: {
        NEXT: 'step-4'
      }
    },
    'step-4': {
      on: {
        NEXT: 'step-5'
      }
    },
    'step-5': {
      on: {
        SUBMIT: 'step-1'
      }
    },
    finished: {}
  }
});

let currentState = insuranceMachine.initialState;

function setStateAttributes(state) {
  // change data-state attribute
  elApp.dataset.state = state;

  // remove any active data-attributes
  document.querySelectorAll(`[data-active]`).forEach(el => {
    delete el.dataset.active;
  });

  // add active data-attributes to proper elements
  document.querySelectorAll(`
    [data-show~="${state}"],
    [data-hide]:not([data-hide~="${state}"])`)
    .forEach(el => {
      el.dataset.active = true;
    });
}

function send(event) {
  currentState = insuranceMachine
    .transition(currentState, event);
  
  setStateAttributes(currentState.value);
}

setStateAttributes(currentState.value);

elNextButtons.forEach(elButton => elButton.addEventListener('click', () => {
  send('NEXT');
}));

elSubmitButton.addEventListener('click', () => {
  send('SUBMIT');
});

// -------------
elAnimationHelp.addEventListener('change', flipping.wrap((e) => {
  if (e.target.checked) {
    elStep3Button.dataset.clickable = true;
  } else {
    delete elStep3Button.dataset.clickable;
  }
}));
              
            
!
999px

Console