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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <div id="nav-bg" class="btn"></div>
<div id="toggle-btn" class="btn">
  <span></span>
  <span></span>
  <span></span>
</div>

<div class="wrapper">
  <nav>
    <ul>
      <li><a class="link" href="#0">Projects</a></li>
      <li><a class="link" href="#0">About</a></li>
      <li><a class="link" href="#0">Contact</a></li>
    </ul>
  </nav>
  
  <div id="content">
    <h1>Floating circle navigation ~60fps animation</h1>
  </div>
</div>


              
            
!

CSS

              
                /* =======
IMPORTS
======= */
@import url('https://fonts.googleapis.com/css?family=Encode+Sans+Condensed:400,600');


/* =========
VARIABLES
========= */
:root {
  --offset-value: 30;
  --btn-size: 60;
  
  --green: #4ECA78;
}


/* =======
WRAPPER
======= */
.wrapper {
  font-family: 'Encode Sans Condensed', sans-serif;
  font-weight: 600;
  height: 100vh;
  width: 100%;
  position: relative;
  background: linear-gradient(to top right, #4ECA78, #D0DB68);
}


/* =====================
NAVIGATION BACKGROUND
===================== */
#nav-bg {
  transform-origin: center center;
  transition: transform .3s;
  transform: translate(var(--translate-x), var(--translate-y)) scale(var(--scale));
  will-change: transform;
  pointer-events: none;
}


/* ======
BUTTON
====== */
.btn {
  position: fixed;
  height: calc(var(--btn-size)*1px);
  width: calc(var(--btn-size)*1px);
  bottom: calc((var(--offset-value))*1px);
  left: calc(var(--offset-value)*1px);
  /*left: calc(50% - (var(--btn-size)/2*1px)); if you wish to center it */
  border-radius: 50%;
  background: #fafafa;
  cursor: pointer;
  margin: 0;
  padding: 0 15px;
  border: none;
  z-index: 100;
  user-select: none;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}

#toggle-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: var(--green);
  /*box-shadow: 0 6px 12px rgba(0,0,0,.1);*/
  transition: transform .3s;
}

#toggle-btn span {
  position: relative;
  width: 100%;
}

#toggle-btn span {
  margin-top: -4px;
}
#toggle-btn span + span {
  margin-top: 8px;
}

#toggle-btn span:before,
#toggle-btn span:after {
  content: '';
  position: absolute;
  top: 0;
  background: currentColor;
  opacity: .8;
  height: 100%;
  width: 50%;
  height: 4px;
  transition: .25s cubic-bezier(.6,0,.3,1);
  transform-origin: center center;
}

#toggle-btn span:before {
  left: 0;
  border-radius: 3px 0 0 3px;
}

#toggle-btn span:after {
  right: 0;
  border-radius: 0 3px 3px 0;
}

#toggle-btn.shown span:nth-of-type(1):before {
  transform: translate3d(3px, 3.5px, 0) rotate(45deg);
}

#toggle-btn.shown span:nth-of-type(1):after {
  transform: translate3d(-3px, 3.5px, 0) rotate(-45deg);
}

#toggle-btn.shown span:nth-of-type(3):before {
  transform: translate3d(3px, -3.5px, 0) rotate(-45deg);
}

#toggle-btn.shown span:nth-of-type(3):after {
  transform: translate3d(-3px, -3.5px, 0) rotate(45deg);
}

#toggle-btn.shown span:nth-of-type(2):before,
#toggle-btn.shown span:nth-of-type(2):after {
  opacity: 0.0001;
}

#toggle-btn.shown span:nth-of-type(2):before {
  transform: translateX(-200%);
}

#toggle-btn.shown span:nth-of-type(2):after {
  transform: translateX(200%);
}

#toggle-btn.shown:before {
  transform: scale(.6);
  transition: .2s;
}

#toggle-btn:before {
  content: '';
  transition: .2s .2s;
  position: absolute;
  top: 3px;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,.1);
  border-radius: inherit;
  filter: blur(5px);
  z-index: -2;
}
#toggle-btn:after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: #fafafa;
  z-index: -1;
}

/* ==========
NAVIGATION
========== */
nav {
  width: 100%;
  height: 100%;
  background: transparent;
  position: fixed;
  top: 0;
  left: 0;
  overflow: hidden;
  display: flex;
  z-index: 200;
  pointer-events: none;
}

nav ul {
  margin: auto;
  pointer-events: auto;
  text-align: center;
}

nav li {
  font-size: 30px;
  color: #212121;
  user-select: none;
  transform: translate(-20px,20px) scale(.9);
  transition: 0s;
  opacity: 0.0001;
  visibility: hidden;
  will-change: transform;
}

nav li + li {
  margin-top: 30px;
}

#toggle-btn.shown ~ .wrapper nav li {
  transform: none;
  opacity: 1;
  visibility: visible;
  transition: .35s cubic-bezier(.4,2.08,.55,1);
}

#toggle-btn.shown ~ .wrapper nav li:nth-child(1) {
  transition-delay: .15s;
}
#toggle-btn.shown ~ .wrapper nav li:nth-child(2) {
  transition-delay: .125s;
}
#toggle-btn.shown ~ .wrapper nav li:nth-child(3) {
  transition-delay: .1s;
}

/* ============
LINK EFFECT
============ */
.link {
  position: relative;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}

.link:before,
.link:after {
  position: absolute;
  content: '';
  height: 3px;
  width: 50%;
  background: #4ECA78;
  top: calc(50% + 2px);
  transition: transform .3s cubic-bezier(.5,.5,0,1);
}

.link:before {
  left: 0;
  transform: translateX(calc(-100% - 10px)) scaleX(0);
  transform-origin: left;
}

.link:after {
  right: 0;
  transform: translateX(calc(100% + 10px)) scaleX(0);
  transform-origin: right;
}

.link:hover:before {
  transform: translateX(calc(-100% - 10px)) scaleX(1);
  transform-origin: right;
}

.link:hover:after {
  transform: translateX(calc(100% + 10px)) scaleX(1);
  transform-origin: left;
}


/* =======
CONTENT
======= */
#content {
  display: flex;
  height: 100%;
}

#content h1 {
  font-size: calc(4vmin + 1em);
  text-align: center;
  margin: auto;
  color: #fff;
  text-shadow: 0 6px 18px rgba(0,0,0,.1);
}




/* Usual suspects */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

a,
a:visited,
a:focus,
a:active,
a:link {
  text-decoration: none;
  outline: 0;
}

a {
  color: currentColor;
  transition: .2s ease-in-out;
}

ul {
  padding: 0;
  list-style: none;
}

img {
  vertical-align: middle;
  height: auto;
  width: 100%;
}
              
            
!

JS

              
                const elem = document.querySelector('#nav-bg'),
      toggleBtn = document.querySelector('#toggle-btn'),
      elemH = elem.getBoundingClientRect().height,
      elemW = elem.getBoundingClientRect().width;

let open = false;
let scale, offsetX, offsetY;

const calculateValues = (() => {
  const w = window.innerWidth;
  const h = window.innerHeight;
  //const cssStyles = getComputedStyle(elem);
  //const offsetValue = Number(cssStyles.getPropertyValue('--offset-value'));
  const offsetValue = Number(getComputedStyle(elem).getPropertyValue('--offset-value'));

  //  Offsets to center the circle
  offsetX = (w/2) - (elemW/2) - offsetValue;
  offsetY = (h/2) - (elemH/2) - offsetValue;

  // Good old pythagoras
  const radius = Math.sqrt((h ** 2)+(w ** 2));
  scale = radius/(elemW/2)/2 + .1; // Add '.1' to compensate for Safari sub pixel blur issue
  return scale;
})


const openMenu = () => {
  elem.style.setProperty("--translate-x", `${offsetX}px`);
  elem.style.setProperty("--translate-y", `-${offsetY}px`);
  elem.style.setProperty("--scale", scale);
}
const closeMenu = () => {
  elem.style.setProperty("--scale", 1);
  elem.style.setProperty("--translate-x", 0);
  elem.style.setProperty("--translate-y", 0);
}
const animateMenu = () => {
  open ? openMenu() : closeMenu();
};

const toggleMenu = () => {
  open = !open;
  animateMenu();
  toggleBtn.classList.toggle('shown');
}

const resizeHandler = () => { 
  window.requestAnimationFrame(() => {
    calculateValues();
    animateMenu();
  });
}

calculateValues();

//toggleBtn.onclick = toggleMenu;
toggleBtn.addEventListener('click', toggleMenu, false);
window.addEventListener("resize", resizeHandler, false);

              
            
!
999px

Console