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

              
                <div class="sky">
  <div id="sun" class="weather-element sun"></div>
  <div class="weather-element cloud hidden"></div>
</div>
<div class="grass"></div>
<div id="cow" class="cow">
  <div class="cow-wrapper">
    <div class="face">
      <div class="eyes">
        <div class="eye eye-left">
          <div class="pupil"></div>
        </div>
        <div class="eye eye-right">
          <div class="pupil"></div>
        </div>
      </div>
      <div id="tongue" class="tongue"></div>
      <div class="snout">
        <div class="nostril nostril-left"></div>
        <div class="nostril nostril-right"></div>
      </div>
    </div>
    <div class="body">
      <div class="spot spot-1"></div>
      <div class="spot spot-3"></div>
    </div>
    <div class="legs">
      <div class="leg leg-bl">
        <div class="hoof"></div>
      </div>
      <div class="leg leg-fl">
        <div class="hoof"></div>
      </div>
      <div class="leg leg-br">
        <div class="hoof"></div>
      </div>
      <div class="leg leg-fr">
        <div class="hoof"></div>
      </div>
    </div>
  </div>
</div>
<div class="info" style="position: absolute;
        right: 30px;
        bottom: 10px;
        color: white;
        font-size: 12px;
        text-align: right;">
  <p><strong>This works best on a desktop browser.</strong></p>
  <p>Hover around and don't forget to click on the sun! - <a href="https://github.com/jasonlutterloh/bessie" style="color:white">Github</a></p>

</div>
              
            
!

CSS

              
                html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}
body {
  background-image: radial-gradient(ellipse at bottom, #a3b2ff, #003dff);
  background-repeat: no-repeat;
  background-size: cover;
  overflow: hidden;
}
/*** Weather Elements ***/
.rainy {
  background-image: radial-gradient(ellipse at bottom, #a3b2ff, #717581);
}
.weather-element {
  position: absolute;
  transition-property: all;
  transition-duration: 1s;
}
.sun {
  width: 10vw;
  height: 10vw;
  min-width: 100px;
  min-height: 100px;
  background-image: radial-gradient(ellipse at center, #fff4a3, #ffcc00);
  box-shadow: 0 0 50px #fff;
  border-radius: 100%;
  right: 8vw;
  top: 5vw;
  display: block;
}
.sun.hidden {
  top: -30vw;
}
.cloud {
  width: 15vw;
  max-width: 160px;
  height: 4vw;
  max-height: 42px;
  background: white;
  border-radius: 2vw;
  margin-top: 4vw;
  top: 3vh;
  right: -30vw;
}
.cloud.hidden {
  right: -300px !important; /*Used to override the random values assigned by js*/
}
.cloud:after {
  content: " ";
  width: 7vw;
  max-width: 75px;
  height: 4vw;
  max-height: 42px;
  background: white;
  display: block;
  position: relative;
  top: -219%;
  left: 20%;
  border-radius: 3vw;
}
.cloud:before {
  content: " ";
  width: 8vw;
  max-width: 85px;
  height: 7vw;
  max-height: 75px;
  background: white;
  display: block;
  position: relative;
  top: -90%;
  left: 36%;
  border-radius: 3vw;
}
.grass {
  position: absolute;
  bottom: 0;
  height: 20vh;
  width: 100vw;
  background-image: radial-gradient(ellipse at center top, #c0ffa3, #1e7e00);
  border-radius: 30% 30% 0 0;
  z-index: -10;
}

/*** Cow Elements ***/
.cow {
  left: calc(50% - 20vw);
  width: 40vw;
  max-width: 426px;
  max-height: 320px;
  height: 30vw;
  bottom: 18vh;
  position: absolute;
}
.cow-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
}
.face {
  width: 25%;
  height: 44%;
  border-radius: 15vw/10vw;
  background: white;
  position: absolute;
  top: 0;
  right: 0;
  z-index: 100;
  transition-property: all;
  transition-duration: 1s;
}
.face:hover {
  transform: rotate(-360deg);
}
.eyes {
  position: absolute;
  width: 100%;
  top: 25%;
}
.eye {
  position: relative;
  display: inline-block;
  width: 30%;
  border-radius: 50%;
  border: 2px solid #000;
  transition-property: all;
  transition-duration: 1s;
  box-sizing: border-box;
}
.eye:after {
  content: "";
  display: block;
  padding-bottom: 100%;
}
.eye-left {
  left: 10%;
}
.eye-right {
  left: 20%;
}
.eye-left:hover {
  transform: rotate(360deg);
}
.eye-right:hover {
  transform: rotate(-360deg);
}
.pupil {
  position: absolute;
  display: block;
  width: 33%;
  height: 33%;
  background: #000;
  border-radius: 50%;
  top: 66%;
  left: 34%;
  transition-property: all;
  transition-duration: 0.5s;
}
.pupil.startled {
  top: 40%;
  left: 36%;
}
.snout {
  width: 110%;
  height: 40%;
  background: pink;
  margin-left: -5%;
  position: relative;
  top: 64%;
  border-radius: 22%/36%;
  transition-property: all;
  transition-duration: 0.5s;
}
.snout:hover {
  transform: scale3d(1.2, 1.2, 1);
}
.nostril {
  position: absolute;
  width: 15%;
  top: 30%;
  height: 36%;
  background: black;
}
.nostril-left {
  left: 24%;
  border-radius: 20% 64%;
}
.nostril-right {
  right: 24%;
  border-radius: 64% 20%;
}
.tongue {
  width: 20%;
  height: 20%;
  position: absolute;
  background-color: rgb(235, 126, 213);
  display: block;
  border-radius: 0 0 30% 30%;
  left: 50%;
  bottom: 0;
  transition-property: all;
  transition-duration: 0.5s;
}
.tongue.out {
  bottom: -16%;
}

/** Body **/
.body {
  width: 96%;
  height: 60%;
  border-radius: 8vw 10vw 15vw 10vw;
  background: white;
  left: 0;
  position: absolute;
  bottom: 14%;
  overflow: hidden;
  transition-property: all;
  transition-duration: 1s;
}
.spot {
  background: #000;
  position: absolute;
}
.spot-1 {
  width: 22%;
  height: 60%;
  left: -4%;
  border-radius: 50%/40%;
}
.spot-1:after {
  width: 129%;
  height: 86%;
  border-radius: 100%;
  left: 20%;
  top: -20%;
  content: " ";
  position: absolute;
  background: #000;
  display: block;
}
.spot-3 {
  width: 46%;
  height: 90%;
  border-radius: 80%/60%;
  right: 0;
  top: 60%;
}
.spot-3:after {
  content: " ";
  height: 100%;
  width: 80%;
  border-radius: 80%/60%;
  right: -20%;
  top: -20%;
  display: block;
  position: absolute;
  background: #000;
}

.legs {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 36%;
}
.leg {
  background: white;
  height: 72%;
  width: 8%;
  position: absolute;
  transition-property: transform;
  transition-duration: 1s;
  border-radius: 45%/15%;
}
.leg-bl {
  bottom: 0;
  left: 26%;
  z-index: -1;
}
.leg-fl {
  bottom: 0;
  left: 72%;
  z-index: -1;
}
.leg-br {
  bottom: -6%;
  left: 16%;
}
.leg-fr {
  bottom: -6%;
  left: 62%;
}
.hoof {
  background-color: #333;
  width: 110%;
  height: 25%;
  position: absolute;
  bottom: 0;
  left: -5%;
  border-radius: 20% 20% 6% 6%;
}

              
            
!

JS

              
                function initSun() {
  $("#sun").click(function () {
    makeItRain();
  });
  makeClouds();
}
function hideSun() {
  var sun = $("#sun");
  sun.off();
  sun.addClass("hidden");
}
function makeItSun() {
  hideClouds();

  $("#sun").removeClass("hidden");
  $("body").removeClass("rainy");
  $(".pupil").removeClass("startled");

  initSun();
}

function makeItRain() {
  hideSun();

  $("body").addClass("rainy");
  $(".pupil").addClass("startled");

  showClouds();
}
function initClouds() {
  $(".cloud").click(function () {
    makeItSun();
  });
}
function showClouds() {
  $(".cloud").removeClass("hidden");
  initClouds();
}
function hideClouds() {
  var clouds = $(".cloud");
  clouds.off();
  clouds.addClass("hidden");
  setTimeout(function () {
    clouds.remove();
  }, 1000);
}
function makeClouds() {
  var clouds = createCloudsMarkup(6);
  $(".sky").append($(clouds));
}
function createCloudsMarkup(numberOfCloudsRequested) {
  var clouds = "";
  // var viewportWidth = $(window).width();
  var cowCoordinates = $(".face").offset();
  var faceHeight =
    typeof cowCoordinates !== "undefined" ? cowCoordinates.top : 200;

  for (var i = numberOfCloudsRequested; i >= 0; i--) {
    var rightValue = generateRandomNumber(100);
    var topValue = generateRandomNumber(faceHeight);
    var cloud =
      "<div class='weather-element cloud hidden' style='right:calc(" +
      rightValue +
      "vw - 7.5vw);top:calc(" +
      topValue +
      "px - 4vw)'></div>";
    clouds += cloud;
  }

  return clouds;
}

function generateRandomNumber(max) {
  var number = 1 + Math.floor(Math.random() * max);
  return number;
}

function initTongue() {
  $(".spot").click(function () {
    $("#tongue")
      .addClass("out")
      .delay(1000)
      .queue(function () {
        $(this).removeClass("out").dequeue();
      });
  });
}

function init() {
  initSun();
  initTongue();
}

init();

              
            
!
999px

Console