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="u-textCenter">
  <h1 class="Title">The<br> Night<br> Sky*</h1>
</div>

              
            
!

CSS

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

$c-orange: #f7933c;
$c-yellow: #fbd773;
$c-white: #ffffff;
$c-blue: #303846;

.sky {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;

  &.is-sticky {
    position: fixed;
    backface-visibility: hidden;
  }

  &.is-bottom {
    top: auto;
    bottom: 0;
  }
}

.star {
  position: absolute;
  width: 0.75em;
  height: 0.25em;
  margin-bottom: 0.25em;
  margin-top: 0.25em;
  background-color: $c-orange;
  opacity: 0.5;
  animation: twinkle1 3s infinite ease-in-out;

  &::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 0.25em;
    height: 1em * (2 / 3);
    margin: auto;
    background-color: $c-yellow;
  }
}

.star--1 {
  animation-name: twinkle2;
  animation-duration: 4s;
}

.star--2 {
  animation-name: twinkle3;
  animation-duration: 5s;
}

@keyframes twinkle1 {
  100%,
  20% {
    opacity: 0.333;
  }

  0% {
    opacity: 0.333;
  }

  10% {
    opacity: 0.6;
  }
}

@keyframes twinkle2 {
  100%,
  30% {
    opacity: 0.25;
  }

  0% {
    opacity: 0.25;
  }

  10% {
    opacity: 0.6;
  }
}

@keyframes twinkle3 {
  100%,
  25% {
    opacity: 0.25;
  }

  0% {
    opacity: 0.25;
  }

  10% {
    opacity: 0.6;
  }
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  align-content: center;
  min-height: 100vh;
  color: $c-white;
  background-color: $c-blue;
}

.Title {
  @include responsive-font(10vw, 50px, 126px, 50px);
  font-family: 'Kanit', Helvetica, Arial, sans-serif;
  font-weight: 800;
  line-height: 0.7;
  text-transform: uppercase;
  position: relative;
  margin: 0.2em;
}

.u-textCenter {
  text-align: center;
}

              
            
!

JS

              
                const $body = document.querySelector("body");
let $sky, count, delay = 0;
let canvas = {
  width: window.innerWidth,
  height: window.innerHeight
};

initSky();
// window.addEventListener('resize', resetSky);

// Random number generator within range
function rng(min, max) {
  return Math.round(Math.random() * (max - min) + min);
}

// Get number of stars based on screen height with a base count of 5
function getStarCount() {
  return Math.round(canvas.height / 100) + 5;
}

function createSky() {
  // Create sky element
  const $newSky = document.createElement("div");
  $newSky.classList.add("sky");
  count = getStarCount();

  // Add star elements to sky
  for (let i = 0; i < count; i++) {
    const $star = createStar();
    $newSky.appendChild($star);
  }

  return $newSky;
}

function createStar() {
  const $star = document.createElement("div");
  const y = rng(0, 100);
  const x = rng(-5, 20);

  // Add base star class and modifier to adjust twinkle timing
  $star.classList.add("star", "star--" + rng(1, 3));

  // Randomly position star to the left or right of the screen
  if (rng(0, 1) === 1) {
    $star.setAttribute(
      "style",
      "top: " + y + "%; left: " + x + "%; animation-delay: " + delay + "ms;"
    );
  } else {
    $star.setAttribute(
      "style",
      "top: " + y + "%; right: " + x + "%; animation-delay: " + delay + "ms;"
    );
  }

  delay += 175;

  return $star;
}

function initSky() {
  $sky = createSky();
  $body.appendChild($sky);

  // Make sky position fixed when infographic hits the top of the screen
  // let waypointTop = new Waypoint({
  //     element: $body[0],
  //     handler: function(direction) {
  //         if (direction === 'down') {
  //             $sky.classList.add('is-sticky');
  //         } else if (direction === 'up') {
  //             $sky.classList.remove('is-sticky');
  //         }
  //     },
  //     offset: 0
  // });

  // Make sky position absolute when infographic hits the bottom of the screen
  // let waypointBottom = new Waypoint({
  //     element: $body[0],
  //     handler: function(direction) {
  //         if (direction === 'down') {
  //             $sky.classList.remove('is-sticky');
  //             $sky.classList.add('is-bottom');
  //         } else if (direction === 'up') {
  //             $sky.classList.add('is-sticky');
  //             $sky.classList.remove('is-bottom');
  //         }
  //     },
  //     offset: 'bottom-in-view'
  // });
}

// function resetSky() {
//     canvas.width = window.innerWidth;
//     canvas.height = window.innerHeight;
//     const $container = $sky.parentElement;
//     const $newSky = createSky();
//
//     if ($container) {
//         $container.replaceChild($newSky, $sky);
//         $sky = $newSky;
//     }
// }

              
            
!
999px

Console