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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <html>

<head>
  <style>
    @import url('https://fonts.googleapis.com/css2?family=Fredoka+One&display=swap');
  </style>
</head>

<body>
  <h1>Night and Day (Using Greensock)</h1>

  <button onclick="toggle()">
    <svg width="105" height="105" viewBox="0 0 105 105" fill="none" xmlns="http://www.w3.org/2000/svg">
      <path id="moon" fill-rule="evenodd" clip-rule="evenodd" d="M46 25C41.1068 25 36.3947 26.2819 32.2482 28.6805C30.5839 29.6433 30.5839 32.0459 32.2482 33.0086C39.157 37.0051 43.5 44.3729 43.5 52.5C43.5 60.6271 39.157 67.9949 32.2482 71.9914C30.5839 72.9541 30.5839 75.3567 32.2482 76.3195C36.3947 78.7181 41.1068 80 46 80C61.1878 80 73.5 67.6878 73.5 52.5C73.5 37.3122 61.1878 25 46 25ZM46.0001 30C58.4265 30 68.5001 40.0736 68.5001 52.5C68.5001 64.9264 58.4265 75 46.0001 75L45.0781 74.9815C42.9339 74.8951 40.8425 74.5081 38.8506 73.8413L38.4976 73.715L38.7003 73.5497C44.8127 68.4099 48.5001 60.7752 48.5001 52.5L48.4878 51.6747C48.2515 43.7186 44.609 36.4188 38.7003 31.4503L38.4976 31.2825L38.8506 31.1587C41.1271 30.3966 43.5335 30 46.0001 30Z" fill="black" />
      <path id="sun" fill-rule="evenodd" clip-rule="evenodd" d="M53 38.2727C44.8663 38.2727 38.2727 44.8663 38.2727 53C38.2727 61.1336 44.8663 67.7273 53 67.7273C61.1336 67.7273 67.7273 61.1336 67.7273 53C67.7273 44.8663 61.1336 38.2727 53 38.2727ZM53.0001 43.1818C58.4225 43.1818 62.8183 47.5775 62.8183 53C62.8183 58.4224 58.4225 62.8181 53.0001 62.8181C47.5777 62.8181 43.1819 58.4224 43.1819 53C43.1819 47.5775 47.5777 43.1818 53.0001 43.1818Z" fill="black" />
      <g id="ray">
        <path class="ray" fill-rule="evenodd" clip-rule="evenodd" d="M77.5 50C78.8807 50 80 51.3431 80 53C80 54.5385 79.0349 55.8065 77.7916 55.9798L77.5 56H72.5C71.1193 56 70 54.6569 70 53C70 51.4615 70.9651 50.1935 72.2084 50.0202L72.5 50H77.5Z" fill="lawngreen" />

        <path class="ray" fill-rule="evenodd" clip-rule="evenodd" d="M69.5 33.7721C70.5294 32.7426 72.1985 32.7426 73.2279 33.7721C74.1782 34.7223 74.2513 36.2176 73.4472 37.2517L73.2279 37.5L69.5 41.2279C68.4706 42.2574 66.8015 42.2574 65.7721 41.2279C64.8218 40.2777 64.7487 38.7824 65.5528 37.7483L65.7721 37.5L69.5 33.7721Z" fill="black" />
        <path class="ray" fill-rule="evenodd" clip-rule="evenodd" d="M53 26C54.5385 26 55.8065 26.9651 55.9798 28.2084L56 28.5V33.5C56 34.8807 54.6569 36 53 36C51.4615 36 50.1935 35.0349 50.0202 33.7916L50 33.5V28.5C50 27.1193 51.3431 26 53 26Z" fill="orange" />
        <path class="ray" fill-rule="evenodd" clip-rule="evenodd" d="M33.7721 33.7721C34.7223 32.8218 36.2176 32.7487 37.2517 33.5528L37.5 33.7721L41.2279 37.5C42.2574 38.5294 42.2574 40.1985 41.2279 41.2279C40.2777 42.1782 38.7824 42.2513 37.7483 41.4472L37.5 41.2279L33.7721 37.5C32.7426 36.4706 32.7426 34.8015 33.7721 33.7721Z" fill="red" />

        <path class="ray" fill-rule="evenodd" clip-rule="evenodd" d="M33.5 50C34.8807 50 36 51.3431 36 53C36 54.5385 35.0349 55.8065 33.7916 55.9798L33.5 56H28.5C27.1193 56 26 54.6569 26 53C26 51.4615 26.9651 50.1935 28.2084 50.0202L28.5 50H33.5Z" fill="purple" />

        <path class="ray" fill-rule="evenodd" clip-rule="evenodd" d="M37.5 65.6863C38.5294 64.7712 40.1985 64.7712 41.2279 65.6863C42.1782 66.531 42.2513 67.8601 41.4472 68.7793L41.2279 69L37.5 72.3137C36.4706 73.2288 34.8015 73.2288 33.7721 72.3137C32.8218 71.469 32.7487 70.1399 33.5528 69.2207L33.7721 69L37.5 65.6863Z" fill="pink" />
        <path class="ray" fill-rule="evenodd" clip-rule="evenodd" d="M53 70C54.5385 70 55.8065 70.9651 55.9798 72.2084L56 72.5V77.5C56 78.8807 54.6569 80 53 80C51.4615 80 50.1935 79.0349 50.0202 77.7916L50 77.5V72.5C50 71.1193 51.3431 70 53 70Z" fill="blue" />

        <path class="ray" fill-rule="evenodd" clip-rule="evenodd" d="M65.7721 65.6863C66.7223 64.8416 68.2176 64.7767 69.2517 65.4914L69.5 65.6863L73.2279 69C74.2574 69.9151 74.2574 71.3987 73.2279 72.3137C72.2777 73.1584 70.7824 73.2233 69.7483 72.5086L69.5 72.3137L65.7721 69C64.7426 68.0849 64.7426 66.6013 65.7721 65.6863Z" fill="yellow" />
      </g>
    </svg>
  </button>
  <div class="command-container">

    <svg width="154" height="161" viewBox="0 0 154 161" fill="none" xmlns="http://www.w3.org/2000/svg">
      <path d="M19.0691 13.3862L21.567 13.2833C21.5697 13.3493 21.5698 13.4154 21.5673 13.4815L19.0691 13.3862ZM16.8092 1.48413C17.7444 0.468434 19.326 0.403235 20.3417 1.3385L36.8934 16.5796C37.9091 17.5149 37.9743 19.0964 37.039 20.1121C36.1038 21.1278 34.5222 21.193 33.5065 20.2577L18.7939 6.71012L5.24625 21.4228C4.31098 22.4385 2.72941 22.5037 1.71371 21.5684C0.698016 20.6331 0.632816 19.0515 1.56808 18.0359L16.8092 1.48413ZM16.5712 13.4892L16.1504 3.28056L21.1461 3.07461L21.567 13.2833L16.5712 13.4892ZM21.5673 13.4815C18.3667 97.419 37.2697 133.955 62.9063 148.025C75.814 155.109 90.7921 156.734 106.334 155.485C121.883 154.235 137.783 150.129 152.421 145.95L153.794 150.758C139.125 154.946 122.816 159.176 106.735 160.469C90.6481 161.761 74.5775 160.134 60.5006 152.408C32.168 136.858 13.3583 97.5434 16.5709 13.291L21.5673 13.4815Z" fill="black" />
    </svg>
    <h1>Click here!!</h1>
  </div>

</body>

</html>
              
            
!

CSS

              
                html {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #b8f2e6;
}

h1 {
  font-family: "Fredoka One", cursive;
  font-weight: 400;
  margin: 0;
}
button {
  background-color: transparent;
  border: none;
  cursor: pointer;

  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;

  transition: all 200ms ease-out;

  outline: none;

  &:hover {
    transform: scale(1.1);
  }
  &:active {
    transform: scale(1);
  }
}

#moon {
  display: none;
}

#ray {
  path {
    fill: black;
  }
}

.command-container {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  transform: translateX(40px);

  h1 {
    margin-left: 30px;
  }
}

              
            
!

JS

              
                let sun = document.getElementById("sun"),
  current = "sun";

const baseAnimation = {
  duration: 0.2,
  ease: "power2"
};

const goToMoon = () =>
  gsap.to("#ray path", {
    ...baseAnimation,
    x: (index) => Math.cos(index * (Math.PI / 4)) * 25,
    y: (index) => -Math.sin(index * (Math.PI / 4)) * 25,
    scale: 0.5,
    opacity: 0
  });

const goToSun = () =>
  gsap.to("#ray path", {
    ...baseAnimation,
    x: (index) => -Math.cos(index * (Math.PI / 4)),
    y: (index) => Math.sin(index * (Math.PI / 4)),
    scale: 1,
    opacity: 1
  });

function toggle() {
  let next = current === "sun" ? "moon" : "sun";
  gsap.to(sun, { duration: 0.2, morphSVG: `#${next}` });
  current === "sun" ? goToMoon() : goToSun();
  current = next;
}

setTimeout(() => toggle(), 1000);

              
            
!
999px

Console