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

              
                <head>
  <link href='https://fonts.googleapis.com/css?family=Gloria+Hallelujah' rel='stylesheet' type='text/css'>
</head>
<body data-state="1">
  <div class="face">
    <div class="eye"></div>
    <div class="eye"></div>
  </div>
  <section class="bubble">
    <div class="pointy-thingy"></div>
  </section>
  <footer>Change browsertabs to piss off Apy!</footer>
</body>
              
            
!

CSS

              
                // number of states
$states: 4;

// state-background-colors
$colors: #c1ff7f #faff7f #ffc17f #f94a4a;

// The Face
$skincolor: #a0f5ff;
$skin: radial-gradient(ellipse, $skincolor 0%, darken($skincolor, 20%) 95%);
$eyesize: 130px;
$facewidth: 260px;
$faceheight: 220px;
$shadow: 0px 5px 10px rgba(0,0,0,.4);
$animationtiming: 1s ease-in-out;

body {
  font-family: 'Gloria Hallelujah', cursive;
  font-size: 20px;
  line-height: 1.5em;
  transition: background $animationtiming;
}

.face {
  position: relative;
  margin: 100px auto;
  width: $facewidth;
  height: $faceheight;
  background: $skin;
  border-radius: 50%;
  box-shadow: $shadow;
  
  // mouth
  &::after {
    content: '';
    position: absolute;
    background: #f9857c;
    transition: all $animationtiming; // yeah, yeah. shouldn't use 'all'…
    // state 1
    width: $facewidth/3.5;
    height: $faceheight/5;
    border-radius: 0 0 90px 90px;
    top: $faceheight/1.4;
    left: $facewidth/2.1;
  }
}

.eye {
  position: absolute;
  width: $eyesize;
  height: $eyesize;
  background: #FFF;
  border-radius: 50%;
  
  // pupils
  &::before {
    content: '';
    position: absolute;
    width: $eyesize/5;
    height: $eyesize/5;
    border-radius: 50%;
    transition: all $animationtiming;
    // state 1
    background: #444;
    top: $eyesize/2.3;
    left: $eyesize/2.4;
  }
  
  // eyelids
  &::after {
    content: '';
    position: absolute;
    background: darken($skincolor, 20%);
    border-radius: 90px 90px 0 0;
    transition: all $animationtiming;
    width: 98%;
    height: 40%;
    left: 1%;
  }
  
  // right eye
  &:nth-child(2) {
    left: 130px;
  }
}

body[data-state='2'] {
  .face {
    // mouth
    &::after {
      width: 70px;
      height: 10px;
      border-radius: 0 0 90px 90px;
      top: 170px;
      left: 140px;
      transform: rotate(-15deg);
    }
  }
  .eye {
    // pupils
    &::before {
      top: 90px;
      left: 30px;
    }
    // eyelids
    &::after {
      left: -4%;
      transform: rotate(-10deg);
    }
    &:nth-child(2) {
      &::after {
        left: 6%;
        transform: rotate(10deg);
      }
    }
  }
}

body[data-state='3'] {
  .face {
    // mouth
    &::after {
      width: 40px;
      height: 10px;
      border-radius: 90px 90px;
      top: 170px;
      left: 140px;
    }
  }
  .eye {
    // pupils
    &::before {
      top: 55px;
      left: 50px;
    }
    // eyelids
    &::after {
      left: 0;
      height: 50%;
      width: 100%;
    }
  }
}

body[data-state='4'] {
  .face {
    // mouth
    &::after {
      width: 70px;
      height: 20px;
      border-radius: 90px 90px 0 0;
      top: 170px;
      left: 140px;
      transform: rotate(-15deg);
    }
  }
  .eye {
    // pupils
    &::before {
      top: 60px;
      left: 50px;
    }
    // eyelids
    &::after {
      height: 50%;
      width: 100%;
      left: 4%;
      transform: rotate(10deg);
    }
    &:nth-child(2) {
      &::after {
        left: -4%;
        transform: rotate(-10deg);
      }
    }
  }
}

// bubble
.bubble {
  position: relative;
  width: 80%;
  min-height: 150px;
  margin: 80px auto;
  background: #FFF;
  border-radius: 30px;
  padding: 1%;
  box-shadow: $shadow;
  word-wrap: break;
  
  &::before {
    // state 1
    content: "Hey, I'm Apy. \A Welcome to my visible World! \A How nice of you to visit me!";
    white-space: pre-wrap;
    position: absolute;
    width: 92%;
    padding: 2% 10%;
    transition: content $animationtiming;
  }

  .pointy-thingy,
  &::after {
    content: '';
    position: absolute;
    width: 80px;
    height: 40px;
    background: #FFF;
    border-radius: 90px 90px 0 0;
    top: -40px;
    left: 60%;
  }
  &::after {
    height: 60px;
    top: -60px;
    left: 58%;
    transition: background $animationtiming;
  }
}

// state messages
body[data-state="2"] {
  .bubble::before {
    content: "Oh, you left… \A Well, but you came back. \A Thought, you wouldn't…";
  }  
}
body[data-state="3"] {
  .bubble::before {
    content: "Really, stop doing that! \A Such a pen window gets really boring all by myself!";
  }  
}
body[data-state="4"] {
  .bubble::before {
    content: "Alright, skrew you! \A I don't want you here anymore! \A Leave me and my window alone, you unaccountable piece of $#%7!";
  }  
}

// state background styling
@for $i from 1 through $states {
  body{
    &[data-state='#{$i}']{
      background: nth($colors, $i);
      
      .bubble::after {
        background: nth($colors, $i);
      }
    }
  }
}

footer {
  position: fixed;
  bottom: 0;
  width: 100%;
  padding: 20px;
  background: rgba(0,0,0,0.4);
  color: #DDD;
  text-align: center;
}
              
            
!

JS

              
                var body    = document.body;
var counter = 0;

document.addEventListener('visibilitychange', function(){
  if(document.hidden) {
    if(counter < 3) {
      counter++;
    }
  }
  else {
    body.setAttribute('data-state', counter + 1);
  }
});
              
            
!
999px

Console