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

              
                <h1>Animated Speech Bubble (Bouncy)</h1>
<p>Hover the mouse over the rectangle and something cool will happen</p>
<div id="Rectangle">
  <div id="SpeechBubble">I'm a rectangle</div>
</div>
              
            
!

CSS

              
                /* Fonts from Google Fonts - more at https://fonts.google.com */
@import url("https://fonts.googleapis.com/css?family=Open+Sans:400,700");
@import url("https://fonts.googleapis.com/css?family=Merriweather:400,700");

body {
  background-color: white;
  font-family: "Open Sans", sans-serif;
  padding: 5px 25px;
  font-size: 18px;
  margin: 0;
  color: #444;
}

h1 {
  font-family: "Merriweather", serif;
  font-size: 32px;
}

/* #Rectangle is given a relative position so that 
#SpeechBubble (its child) can be positioned correctly. 
Without this step, #SpeechBubble  will be positioned 
relative to the body instead */
#Rectangle {
  margin: 90px auto;
  background-color: #ff5a5a;
  width: 100px;
  height: 200px;
  position: relative;
}

/* #SpeechBubble is set as a child of #Rectangle to make positioning
it easier. #SpeechBubble is given an absolute position so that its 
position is relative to the #Rectangle (its parent). Its scale is 
set to zero since it should only appear when the mouse hovers over
#Rectangle. The 'animation-fill-mode' property is set to 'forwards' 
so that  the scale value stays at 1 after the animation finishes, 
otherwise  #SpeechBubble will disappear once the animation finishes. 
The 'animation-name' property is omitted since it's going to be 
set by jQuery instead */
#SpeechBubble {
  position: absolute;
  transform-origin: 0% 100%;
  text-align: center;
  background-color: #5a5a5a;
  color: white;
  border-radius: 10px;
  width: 120px;
  padding: 10px;
  left: 110px;
  top: -75px;
  transform: scale(0);
  animation-fill-mode: forwards;
}
/* We need to add a tail to the speech bubble. This is done using
the ::before pseudo-element. The tail's size is controlled by 
its borders. The right and bottom borders are given a transparent
color so that the tail still retains its shape while giving the
desired look */
#SpeechBubble::before {
  content: "";
  display: block;
  width: 0;
  position: absolute;
  bottom: -25px;
  left: 5px;
  border-style: solid;
  border-width: 15px;
  border-color: #5a5a5a transparent transparent #5a5a5a;
  transform: rotate(10deg);
}

/* Here the scale changes from 0 to 1. To add the bounciness 
effect, the scale is set to 1.25 midway through the animation
to give the animation a nicer effect. */
@keyframes expand-bounce {
  0% {
    transform: scale(0);
  }
  50% {
    transform: scale(1.25);
  }
  100% {
    transform: scale(1);
  }
}

/* Here the scale simply goes from 1 back to 0 */
@keyframes shrink {
  0% {
    transform: scale(1);
  }
  100% {
    transform: scale(0);
  }
}

              
            
!

JS

              
                var rectangle = $("#Rectangle");
var speechBubble = $("#SpeechBubble");

// The the user hovers the mouse over
// the rectangle the "expand-bounce"
//animation is called and the duration
// is set to 250 miliseconds.
// When the user moves the mouse away
// the "shrink" animation gets called
// and the duration is set to 100
// miliseconds.
rectangle.hover(
  function() {
    speechBubble.css({
      "animation-name": "expand-bounce",
      "animation-duration": "0.25s"
    });
  },
  function() {
    speechBubble.css({
      "animation-name": "shrink",
      "animation-duration": "0.1s"
    });
  }
);

              
            
!
999px

Console