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.

            
              <div>
  <input type="checkbox" class="control" id="control">
  <label for="control">enable microanimations</label>
  <a href="" class="nav-toggle">
    <span></span>
    
  </a>
  <nav>
      <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">Work</a></li>
        <li><a href="#">Team</a></li>
        <li><a href="#">Contact</a></li>
        <li><a href="#">Help</a></li>
      </ul>
    </nav>
</div>
            
          
!
            
              $checkSize: 30px;
$toggleSize: 50px;

body {
  background: #333;
  > div {
    margin: 2em;
  }
}

input.control {
  dipslay: none;
  position: absolute;
  top: -999em;
  + label {
    position: relative;
    display: block;
    padding-left: $checkSize*2.5;
    line-height: $checkSize;
    color: #ccc;
    cursor: pointer;
    &:after {
      content: '';
      display: block;
      width: $checkSize*2;
      height: $checkSize;
      background-color: #ccc;
      border-radius: $checkSize;
      position: absolute;
      top: 0;
      left: 0;
      transition: background-color 500ms ease;
    }

    
    &:before {
      content: '';
      display: block;
      width: $checkSize;
      background: white;
      height: $checkSize;
      border-radius: $checkSize;
      box-shadow: 0 0 3px rgba(0,0,0,0.3);
      position: absolute;
      left: 0;
      top: 0;
      transition: left 500ms ease;
      z-index: 10;
    }
  }
  &:checked {
    + label {
      &:after {
        background-color: #38ef7d;
      }
      
      &:before {
        left: $checkSize;
      }
    }
  }
}

.nav-toggle {
  width: $toggleSize;
  height: $toggleSize;
  display: block;
  background: white;
  border-radius: 50%;
  position: fixed;
  top: 2em;
  right: 2em;
  z-index: 100;
  span {
    display: block;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: black;
    width: 30px;
    height: 4px;
    &:before,
    &:after {
      content: '';
      display: block;
      width: 30px;
      height: 4px;
      background: black;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }
    &:before {
      transform: translate(-50%,-250%);

    }
    &:after {
      transform: translate(-50%, 150%);
    }
    
    
  }
  &.clicked {
    span {
      width: 0;
      &:before {
        transform: translate(-50%,-50%) rotate(45deg);
      }
      &:after {
        transform: translate(-50%,-50%) rotate(-45deg);
      }
    }
    + nav {
      ul {
        li {
          opacity: 1;
          @for $i from 1 through 5 {
              &:nth-child(#{$i}) {
                transform: translate(0, ($toggleSize + 10px) * $i ) !important;
              }
            }
        }
      }
    }
  }
}

nav {
  position: fixed;
  top: 2em;
  right: 2em;
  width: $toggleSize;
  height: $toggleSize;
  
  ul {
    list-style: none;
    margin: 0;
    padding: 0;
    li {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      background: #f2f2f2;
      border-radius: 50%;
      a {
        color: black;
        text-decoration: none;
        font-weight: bold;
        width: $toggleSize;
        height: $toggleSize;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 12px;
      }
    }
  }
}

/* MICROANIMATIONS */
input.control:checked {
  & + label {
    & + .nav-toggle {
      box-shadow: 0;
      transition: box-shadow 500ms ease, transform 500ms ease;
      &:hover {
        box-shadow: 0 0 10px rgba(0,0,0,1);
        transform: scale(0.97);
        & + nav {
          ul {
            li {
              @for $i from 1 through 5 {
                &:nth-child(#{$i}) {
                  opacity: 1;
                  transform: translate(0, 4px * $i );
                }
              }
            }
          }
        }
      }
      
      span {
        transition: width 500ms ease;
        &:after,
        &:before {
          transition: transform 500ms ease 200ms;
        }
      }
      & + nav {
        transition: transform 500ms ease;
        ul {
          li {
            opacity: 0;
            transition: transform 500ms ease, opacity 500ms ease;
            @for $i from 1 through 5 {
              &:nth-child(#{$i}) {
                transition-delay: 20ms * $i;
              }
            }
            
            
          }
        }
        
      }
      &.clicked + nav {
        
        ul {
          li {
            opacity: 1;
            
          }
        }
      }
    }
    
  }
}
            
          
!
            
              let toggle = document.querySelector('.nav-toggle');
toggle.addEventListener('click', (e) => {
  e.preventDefault();
  toggle.classList.toggle('clicked');
})

// isn't needed
let label = document.querySelector('.control + label');
label.addEventListener('click', (e) => {
  e.preventDefault();
  document.querySelector('.control').checked = !document.querySelector('.control').checked;
})
            
          
!
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