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

              
                <h2>Cuckoo Clock CSS Animation with Sound</h2>

<div id="clock" class="clock">
  <audio id="cuckooSound" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/cuckoo-sound.mp3" preload="auto">
    Your browser does not support the <code>audio</code> element.
  </audio>
  <div class="cuckoo-head">
    <div class="eye1"></div>
    <div class="eye2"></div>

    <div class="beak-container"></div>
  </div>
</div>

<div class="buttons">
  <button id="play">Play</button>
  <button id="reset">Reset</button>
</div>

<p class="p">Demo by Mihaela Jurkovic. <a href="http://www.sitepoint.com/syncing-css-animations-with-html5-audio" target="_blank">See article</a>.</p>
              
            
!

CSS

              
                body {
  background-color: #222;
  color: #eaeaea;
  margin: 0;
  overflow: hidden;
  padding: 1em;
  text-align: center;
}
/**
 *   Clock container
 *   Change the size here
 */

.clock {
  background-color: black;
  border: 10px ridge black;
  border-color: #ccc #333 #111 #999;
  border-radius: 8%;
  height: 300px;
  margin: 3em auto 1em;
  perspective: 700px;
  perspective-origin: center;
  position: relative;
  /* context for pseudo elements */
  
  text-align: center;
  width: 300px;
}
/**
 *   door
 */

.clock::after {
  background-color: goldenrod;
  border-radius: 5%;
  content: "";
  height: 100%;
  left: 0;
  position: absolute;
  top: 0;
  /* performance boost hardware acceleration activated in 3D */
  
  transform: translateZ(0);
  transform-origin: 100% 100%;
  width: 100%;
}

.cuckoo-head {
  background: #1f1f1f;
  /* Old browsers */
  
  background: linear-gradient(to bottom, #1f1f1f 0%, #7d7e7d 100%);
  border-radius: 50% 50% 25% 25%/50% 50% 50% 50%;
  height: 80%;
  left: 50%;
  margin-left: -40%;
  margin-top: -40%;
  position: absolute;
  top: 55%;
  width: 80%;
}
/**
 *   feather
 */

.clock::before {
  border-radius: 50%;
  box-shadow: 1em 1em 0 0 #1f1f1f;
  content: "";
  display: block;
  height: 30%;
  left: 20%;
  position: absolute;
  top: -6%;
  width: 30%;
  z-index: -1;
}

.eye1,
.eye2 {
  background-color: yellow;
  border-radius: 50%;
  box-shadow: 0 -2px 5px black;
  height: 10%;
  left: 30%;
  position: absolute;
  top: 30%;
  width: 10%;
}

.eye2 {
  left: 60%;
}

.eye1::after,
.eye2::after {
  background-color: black;
  border-radius: 50%;
  content: "";
  display: block;
  height: 60%;
  left: 20%;
  position: absolute;
  top: 30%;
  width: 60%;
}

.beak-container {
  height: 40%;
  left: 30%;
  position: absolute;
  top: 40%;
  /* animation rotation will be applied to the container */
  
  transform: translateZ(0) rotateX(0);
  width: 40%;
}

.beak-container::after {
  background: #febf04;
  /* Old browsers */
  
  background: linear-gradient(135deg, #febf04 0%, #ffd65e 100%);
  border-top-left-radius: 20%;
  border-top-right-radius: 5%;
  border-bottom-right-radius: 75%;
  border-bottom-left-radius: 5%;
  box-shadow: -1px -1px 5px black;
  content: "";
  left: 0;
  position: absolute;
  height: 100%;
  top: 0;
  width: 100%;
  /** position the beak right side up */
  
  transform: rotate(45deg);
}

.clock.active::after {
  animation: door 2.1s linear 0s 1;
}

.clock.active .cuckoo-head {
  animation: head 2.1s linear 0s 1;
}

.clock.active .beak-container {
  animation: beak 2.1s linear 0s 1;
}

.#clock.active .eye1,
.clock.active .eye2 {
  animation: eyes 2.1s linear 0s 1;
}

.clock.active::before {
  animation: feather 2.1s linear 0s 1;
}

@keyframes door {
  0% {
    background-color: goldenrod;
    transform: translateZ(0) rotateY(0deg);
  }
  14% {
    background-color: #5d0000;
    transform: translateZ(0) rotateY(90deg);
  }
  31% {
    background-color: #5d0000;
    transform: translateZ(0) rotateY(90deg);
  }
  33% {
    background-color: goldenrod;
    transform: translateZ(0) rotateY(0deg);
  }
}

@keyframes head {
  14% {
    transform: translateZ(0) scaleY(1);
  }
  23% {
    transform: translateZ(0) scaleY(0.9);
  }
  31% {
    transform: translateZ(0) scaleY(1);
  }
}

@keyframes beak {
  14% {
    transform: translateZ(0) rotateX(0);
  }
  23% {
    transform: translateZ(0) rotateX(60deg);
  }
  31% {
    transform: translateZ(0) rotateX(0);
  }
}

@keyframes eyes {
  14% {
    transform: translateZ(0) scaleY(1);
  }
  23% {
    transform: translateZ(0) scaleY(0.3);
  }
  31% {
    transform: translateZ(0) scaleY(1);
  }
}

@keyframes feather {
  14% {
    transform: translateZ(0) scaleY(1);
    top: -6%;
  }
  23% {
    transform: translateZ(0) scaleY(0.5);
    top: 3%;
  }
  31% {
    transform: translateZ(0) scaleY(1);
    top: -6%;
  }
}

.buttons {
  text-align: center;
  color: black;
}

button {
  padding: 4px 16px;
}

.p {
  text-align: center;
  font-size: 13px;
  padding-top: 120px;
}

.p a {
  color: white;
}
              
            
!

JS

              
                var playBtn = document.getElementById('play'),
  resetBtn = document.getElementById('reset'),
  standrew = document.getElementById('clock'),
  cuckooSound = document.getElementById('cuckooSound');

playBtn.addEventListener('click', function() {
  if (!clock.classList.contains('active')) {
    clock.classList.add('active');
    cuckooSound.play();
  }
}, false);

resetBtn.addEventListener('click', function() {
  clock.classList.remove('active');
  cuckooSound.pause();
  cuckooSound.currentTime = 0;
}, false);
              
            
!
999px

Console