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

              
                <main class="wrapper">
  <div class="planet planet--1">
    <div class="background"></div>
    <div class="radius"></div>
    <div class="particle particle--1"></div>
    <div class="particle particle--2"></div>
    <div class="particle particle--3 nb"></div>
    <div class="particle particle--4 nb"></div>
    <div class="particle particle--5 nb"></div>
  </div>
  <div class="planet planet--2">
    <div class="background"></div>
    <div class="radius"></div>
    <div class="radius radius--secondary"></div>
    <div class="particle particle--1"></div>
    <div class="particle particle--2"></div>
    <div class="particle particle--3 nb"></div>
    <div class="particle particle--4 nb"></div>
    <div class="particle particle--5 nb"></div>

  </div>
  <div class="planet planet--3">
    <div class="background"></div>
    <div class="particle particle--1"></div>
    <div class="particle particle--2"></div>
    <div class="particle particle--3"></div>
    <div class="radius"></div>
  </div>
  <div class="planet planet--4">
    <div class="background"></div>
    <div class="particle particle--1"></div>
    <div class="particle particle--2"></div>
    <div class="particle particle--3 nb"></div>
    <div class="particle particle--4 nb"></div>
    <div class="particle particle--5 nb"></div>
    <div class="particle particle--6 nb"></div>
  </div>
</main>

<div class="control">
  <label class="label label--prev" for="range" id="label-prev" data-planet="Uranus"></label>
  <label class="label label--curr" for="range" id="label-curr" data-planet="Uranus" data-prev="0"></label>
  <input type="range" min="0" max="3" step="1" value="0" id="range"> 
</div>
              
            
!

CSS

              
                $color-primary: #3FB4C0;
$border-color: #333;

/* BASIC STYLING */
html {
  height: 100%;
  display: flex;
}

body {
  position: relative;
  margin: auto;
  color: #ddd;
  background: #f5f5f5;
}

.wrapper {
  position: relative;
  height: 20vmin;
  width: 20vmin;
  margin: 0 auto;
}

/* PLANET STYLING */
.planet {
  --planet-color: #ffd260;
  --particle-color: #3FB4C0;
  --rotation: 30deg;
  position: absolute;
  width: 100%;
  height: 100%;

  &--1 {
    --planet-color: #3FB4C0;
    --particle-color: #FEDB82;
    --rotation: 20deg;

    .particle {
      &--1 {
        top: 60%;
        left: 20%;
        width: 10%;
        height: 10%;
      }

      &--2 {
        top: 0%;
        left: 70%;
        width: 16%;
        height: 16%;
      }

      &--3 {
        top: 60%;
        left: 40%;
        width: 5%;
        height: 5%;
      }

      &--4 {
        top: 100%;
        left: 10%;
        width: 8%;
        height: 8%;
      }

      &--5 {
        top: 10%;
        width: 6%;
        height: 6%;
      }
    }
  }
  
  &--2 {
    --planet-color: #FF5B25;
    --particle-color: #FECD6A;
    --rotation: 10deg;
    --rotation-secondary: -10deg;
    
    .particle {
      &--1 {
        top: -5%;
        left: 90%;
        width: 10%;
        height: 10%;
      }

      &--2 {
        top: -8%;
        left: 75%;
        width: 5%;
        height: 5%;
      }
      
      &--3 {
        top: 35%;
        left: 15%;
        width: 5%;
        height: 5%;
      }
      
      &--4 {
        top: 35%;
        left: 65%;
        width: 12%;
        height: 12%;
      }
      
      &--5 {
        top: 55%;
        left: 35%;
        width: 10%;
        height: 10%;
      }
    }
  }
  
  &--3 {
    --planet-color: #7DCCF3;
    --particle-color: #B7D275;
    --rotation: 5deg;
    
    .particle {
      &--1 {
        top: 25%;
        left: 65%;
        width: 20%;
        height: 20%;
      }
      
      &--2 {
        top: 15%;
        left: 25%;
        width: 7%;
        height: 7%;
      }
      
      &--3 {
        top: 45%;
        left: 20%;
        width: 20%;
        height: 35%;
      }
    }
  }
  
  &--4 {
    --planet-color: #EBF3FF;
    --particle-color: #CBEBFD;
    --rotation: 5deg;
    
    .particle {
      &--1 {
        top: 75%;
        left: 30%;
        width: 9%;
        height: 9%;
      }
      
      &--2 {
        top: 40%;
        left: 75%;
        width: 12%;
        height: 12%;
      }
      
      &--3 {
        top: 65%;
        left: 45%;
        width: 6%;
        height: 6%;
      }
      
      &--4 {
        top: 65%;
        left: 15%;
        width: 4%;
        height: 4%;
      }
      
      &--5 {
        top: 30%;
        left: 70%;
        width: 5%;
        height: 5%;
      }
      
      &--6 {
        top: 75%;
        left: 65%;
        width: 8%;
        height: 8%;
      }
    }
  }
}

.particle {
  position: absolute;
  border-radius: 50%;
  border: 0.45vmin solid $border-color;
  background: var(--particle-color);
  transform-origin: 50% 50%;
  opacity: 0;
  
  &.nb {
    border: none;
    background: $border-color;
  }
}

.background {
  position: absolute;
  border-radius: 50%;
  width: 100%;
  height: 100%;
  border: 0.5vmin solid $border-color;
  background: var(--planet-color, #7DCCF3);
  box-shadow: inset -6px -6px 0px 2px rgba(0, 0, 0, 0.15);
  transform-origin: 50% 50%;
  opacity: 0;
}

.radius {
  position: absolute;
  top: 60%;
  left: 50%;
  width: 122%;
  height: 30%;
  opacity: 0;
  border: 0.5vmin solid $border-color;
  border-radius: 50%;
  border-top-color: transparent;
  transform-origin: 50% 50%;
  transform: translate(-50%, -50%) rotate(var(--rotation, 30deg));
  
  &--secondary {
    transform: translate(-50%, -50%) rotate(var(--rotation-secondary, 30deg));
  }
}

/* RANGE AND LABEL */
.control {
  position: relative;
  margin: 40px 0 0 0;
  text-align: center;
}

.label {
  text-transform: uppercase;
  font-weight: bold;
  font-size: 25px;
  margin: 50px 0 5px;
  font-family: Arial Rounded MT Bold, Helvetica Neue, Helvetica, sans serif;
  position: absolute;
  top: 0%;
  left: 50%;
  transform: translate(-50%, -50%);
  transform-origin: 50% 50%;

  &:before {
    content: attr(data-planet);
  }

  &--prev {
    opacity: 1;
  }
}

/*
 https://css-tricks.com/styling-cross-browser-compatible-range-inputs-css/
 https://github.com/darlanrod/input-range-scss
*/

$track-color: #ddd !default;
$thumb-color: $color-primary !default;

$thumb-radius: 50% !default;
$thumb-height: 26px !default;
$thumb-width: 26px !default;
$thumb-shadow-size: -2px !default;
$thumb-shadow-blur: 0 !default;
$thumb-shadow-color: rgba(0, 0, 0, .2) !default;
$thumb-border-width: 0.4vmin !default;
$thumb-border-color: $border-color !default;

$track-width: 100% !default;
$track-height: 6px !default;
$track-border-width: 0 !default;
$track-border-color: #cfd8dc !default;

$track-radius: 5px !default;
$contrast: 0% !default;

@mixin track {
  cursor: pointer;
  height: $track-height;
  transition: all .2s ease;
  width: $track-width;
}

@mixin thumb {
  background: var(--planet-color, $thumb-color);
  border: $thumb-border-width solid $thumb-border-color;
  border-radius: $thumb-radius;
  cursor: pointer;
  height: $thumb-height;
  width: $thumb-width;
  box-shadow: inset
    $thumb-shadow-size
    $thumb-shadow-size
    $thumb-shadow-blur
    $thumb-shadow-color;
  transition: background 1s cubic-bezier(0.5, 0, 0.5, 1);
}

[type='range'] {
  -webkit-appearance: none;
  margin: $thumb-height / 2 0;
  width: $track-width;

  &:focus {
    outline: 0;

    &::-webkit-slider-runnable-track {
      background: lighten($track-color, $contrast);
    }

    &::-ms-fill-lower {
      background: $track-color;
    }

    &::-ms-fill-upper {
      background: lighten($track-color, $contrast);
    }
  }

  &::-webkit-slider-runnable-track {
    @include track;
    background: $track-color;
    border: $track-border-width solid $track-border-color;
    border-radius: $track-radius;
  }

  &::-webkit-slider-thumb {
    @include thumb;
    -webkit-appearance: none;
    margin-top: ((-$track-border-width * 2 + $track-height) / 2) -
      (
        $thumb-height / 2
      );
  }

  &::-moz-range-track {
    @include track;
    background: $track-color;
    border: $track-border-width solid $track-border-color;
    border-radius: $track-radius;
  }

  &::-moz-range-thumb {
    @include thumb;
  }

  &::-ms-track {
    @include track;
    background: transparent;
    border-color: transparent;
    border-width: ($thumb-height / 2) 0;
    color: transparent;
  }

  &::-ms-fill-lower {
    background: darken($track-color, $contrast);
    border: $track-border-width solid $track-border-color;
    border-radius: $track-radius * 2;
  }

  &::-ms-fill-upper {
    background: $track-color;
    border: $track-border-width solid $track-border-color;
    border-radius: $track-radius * 2;
  }

  &::-ms-thumb {
    @include thumb;
    margin-top: 0;
  }
  }

              
            
!

JS

              
                let currentIndex, prevIndex, currentAnimation;
let isAnimating = false;
const sequences = [];
const planets = Array.prototype.slice.call(document.querySelectorAll(".planet"));
const range = document.getElementById("range");
const label = document.getElementById("label-curr");
const labelPrev = document.getElementById("label-prev");
const planetNames = [
  "Uranus",
  "Mars",
  "Earth",
  "Moon"
];
const planetColors = [
  '#3FB4C0',
  '#FF5B25',
  '#7DCCF3',
  '#EBF3FF'
];

// timings for the different planet parts
const timings = {
  background: {
    fill: "forwards",
    duration: 800,
    direction: "normal",
    easing: "cubic-bezier(0.2, 0, .3, 1.5)"
  },
  planet: {
    fill: "none",
    duration: 800,
    direction: "normal",
    easing: "cubic-bezier(.5, 0, .3, 1)"
  },
  particles: {
    fill: "forwards",
    duration: 250,
    direction: "normal",
    easing: "cubic-bezier(.5, 0, .5, 2)"
  },
  radius: {
    fill: "forwards",
    duration: 500,
    direction: "normal",
  }
};

// different effects to use for the planets
const effects = {
  scale: [
    { transform: "scale(0.74)", opacity: 0 },
    { transform: "scale(1)", opacity: 1 }
  ],
  scaleTop: [
    { transform: "translate(-50%, -100%) scale(0.6)", opacity: 0 },
    { transform: "translate(-50%, -50%)  scale(1)", opacity: 1 }
  ],
  fadeInLeft: [
    { transform: "translate(-100%, 0%) scale(0.6)", opacity: 0 },
    { transform: "translate(0, 0)  scale(1)", opacity: 1 }
  ],
  fadeInRight: [
    { transform: "translate(100%, 0%) scale(0.6)", opacity: 0 },
    { transform: "translate(0, 0)  scale(1)", opacity: 1 }
  ],
  fadeOutLeft: [
    { transform: "translate(0, 0)  scale(1)", opacity: 1 },
    { transform: "translate(-100%, 0%) scale(0.6)", opacity: 0 }
  ],
  fadeOutRight: [
    { transform: "translate(0, 0)  scale(1)", opacity: 1 },
    { transform: "translate(100%, 0%) scale(0.6)", opacity: 0 }
  ],
  opacity: [{ opacity: 0 }, { opacity: 1 }]
};

// create the fadeIn effect for the planet
function createFadeInEffect({ el, direction }) {
  const fadeIn = direction === "left"
    ? effects.fadeInLeft
    : effects.fadeInRight;
  const bg = el.querySelector(".background");
  const radius = Array.prototype.slice.call(el.querySelectorAll(".radius"));
  const particles = Array.prototype.slice.call(
    el.querySelectorAll(".particle")
  );
  const particleEffects = [];
  const radiusEffects = [];

  particles.map(el => {
    const effect = new KeyframeEffect(el, effects.scale, timings.particles);
    particleEffects.push(effect);
  });

  radius.map(el => {
    const effect = new KeyframeEffect(el, effects.opacity, timings.radius);
    radiusEffects.push(effect);
  });

  const sequence = new SequenceEffect([
    new KeyframeEffect(bg, fadeIn, timings.background),
    ...particleEffects,
    ...radiusEffects
  ]);

  return sequence;
}

// create the fade out effect for the planet
function createFadeOutEffect({ el, direction }) {
  const fadeOut = direction === "left"
    ? effects.fadeOutLeft
    : effects.fadeOutRight;
  const effect = new KeyframeEffect(el, fadeOut, timings.planet);
  return effect;
}

// create all the effects for the planets
planets.map(planet => {
  const inLeft = createFadeInEffect({ el: planet, direction: "left" });
  const inRight = createFadeInEffect({ el: planet, direction: "right" });
  const outLeft = createFadeOutEffect({ el: planet, direction: "left" });
  const outRight = createFadeOutEffect({ el: planet, direction: "right" });
  sequences.push({ inLeft, inRight, outLeft, outRight });
});

// timings for the label of the range element
const timingsLabel = {
  in: {
    fill: "forwards",
    duration: 1000,
    direction: "normal",
    easing: "cubic-bezier(.5, 0, .5, 1)"
  },
  out: {
    fill: "forwards",
    duration: 900,
    direction: "normal",
    easing: "cubic-bezier(.5, 0, .5, 1)"
  }
};

// effect for the label of the range element
const effectsLabel = {
  fadeInLeft: [
    { transform: "translate(-150%, -50%) scale(0.5)", opacity: 0 },
    { transform: "translate(-50%, -50%) scale(1)", opacity: 1 }
  ],
  fadeInRight: [
    { transform: "translate(50%, -50%) scale(0.5)", opacity: 0 },
    { transform: "translate(-50%, -50%) scale(1)", opacity: 1 }
  ],
  fadeOutLeft: [
    { transform: "translate(-50%, -50%) scale(1)", opacity: 1 },
    { transform: "translate(-150%, -50%) scale(0.5)", opacity: 0 }
  ],
  fadeOutRight: [
    { transform: "translate(-50%, -50%) scale(1)", opacity: 1 },
    { transform: "translate(50%, -50%) scale(0.5)", opacity: 0 }
  ]
};

// animation to play when range is updated
const labelAnimations = {
  inLeft: new GroupEffect([
    new KeyframeEffect(labelPrev, effectsLabel.fadeOutRight, timingsLabel.out),
    new KeyframeEffect(label, effectsLabel.fadeInLeft,  timingsLabel.in)
  ]),
  inRight: new GroupEffect([
    new KeyframeEffect(labelPrev, effectsLabel.fadeOutLeft,  timingsLabel.out),
    new KeyframeEffect(label, effectsLabel.fadeInRight,  timingsLabel.in)
  ])
};

// main function calling all the things on update
function updateSlider(index) {
  // only animate if no animation is running
  if (!isAnimating) {
    const prevLabel = label.getAttribute("data-planet");
    const direction = index > prevIndex ? 1 : 0;
    prevIndex = index;
    
    label.setAttribute("data-planet", planetNames[index]);
    label.setAttribute("data-prev", index);
    labelPrev.setAttribute("data-planet", prevLabel);
    playAnimation(index, direction);
  } else {
    setTimeout(() => updateSlider(index), 800)
  }
}

// playing the right animation depending on the update direction
function playAnimation(index, direction) {
  const label = direction ? labelAnimations.inLeft : labelAnimations.inRight;
  const sequence = direction ? sequences[index].inLeft : sequences[index].inRight;

  // play the label animation
  isAnimating = true;
  document.timeline.play(label);

  // get the planet animation and pause until fade out complete
  let planetAnim = document.timeline.play(sequence);
  setAnimation(planetAnim, index);
  
  // update range thumb color
  range.style.setProperty(`--planet-color`, planetColors[index]);
  
  // if another planet is already visible
  if (currentIndex) {
    // play the fade out animation
    const outSequence = direction ? sequences[currentIndex].outRight : sequences[currentIndex].outLeft;
    let outAnim = document.timeline.play(outSequence);

    // play the current animation, when the out animation is finished
    outAnim.onfinish = () => {
      currentAnimation.cancel();
      planetAnim.play()
    };
  } else {
    planetAnim.play()
  }
}

function setAnimation(animation, index) {
  animation.currentTime = 0;
  animation.pause();
  animation.onfinish = () => {
    currentIndex = index;
    currentAnimation = animation;
    isAnimating = false;
  };
}


// add eventListener with lodash debounce
range.addEventListener(
  "input",
  _.debounce(e => updateSlider(e.target.value), 300)
);

updateSlider('0');
              
            
!
999px

Console