cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              <!-- 

Please enable your microphone.

Please click inside of the preview window to activate sound effects. 

-->

<h1>Say Either:<br><span>'Lock'</span> or <span>'Unlock'</span></h1>
<h2>(or just click the padlock 🔒)</h2>

<div class="padlock">
    <div class="keyhole"></div>
</div>

<p class="heard">Heard: <span class="heard-output">nothing</span></p>

<audio src="https://www.freesfx.co.uk/rx2/mp3s/6/18041_1464275440.mp3" class="padlock-open"></audio>
<audio src="https://www.freesfx.co.uk/rx2/mp3s/6/18043_1464275440.mp3" class="padlock-close"></audio>
            
          
!
            
              /*

Padlock design inspired by Chris Cacioppe on Dribbble:

https://dribbble.com/shots/4009114-Unlock-Animation

*/

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-family: "Roboto", Arial, sans-serif;
    font-weight: 700;
    text-align: center;
    color: #eee;
    background-color: #8077e7;
    padding: 15px;
}

h1 {
    font-size: 50px;
    line-height: 1.2;
    margin-bottom: 8px;
}

h1 span {
    font-size: 52px;
    color: #77e7ad;
}

h2 {
    font-size: 17px;
    margin-bottom: 35px;
}

.heard {
    font-size: 35px;
    margin-top: 25px;
}

.heard-output {
    color: #77e7ad;
}

.padlock {
    position: relative;
    width: 260px;
    height: 200px;
    background-image: linear-gradient(
        to bottom right,
        #f2bc23 49.9%,
        #eab02a 50%
    );
    border-radius: 20px 20px 100px 100px;
    margin-top: 125px;
    cursor: pointer;
}

.padlock.unlock::before {
    transform: translate(-50%, -60%);
}

.padlock.unlock::after {
    transform: translate(-50%, calc(-50% - 15px)) rotate(90deg);
}

.padlock::before {
    content: "";
    position: absolute;
    left: 50%;
    z-index: -1;
    width: 200px;
    height: 250px;
    border-radius: 125px;
    border: 40px solid #dbe1e4;
    transform: translate(-50%, -50%);
    transition: transform 300ms cubic-bezier(0.17, 0.67, 0.65, 1.52);
    -webkit-clip-path: polygon(0% 0%, 100% 0%, 100% 65%, 50% 65%, 50% 57%, 22% 57%, 22% 51%, 15% 51%, 14% 52%, 14% 53%, 15% 54%, 22% 54%, 18% 57%, 2% 57%, 0% 55%);
            clip-path: polygon(0% 0%, 100% 0%, 100% 65%, 50% 65%, 50% 57%, 22% 57%, 22% 51%, 15% 51%, 14% 52%, 14% 53%, 15% 54%, 22% 54%, 18% 57%, 2% 57%, 0% 55%);
}

.padlock::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 1;
    width: 20px;
    height: 100px;
    background-image: linear-gradient(to right, #ccc 49.9%, #aaa 50%);
    border-radius: 10px;
    transform: translate(-50%, calc(-50% - 15px));
    transition: transform 180ms;
}

.keyhole {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 60px;
    height: 60px;
    background-color: #2d3237;
    border-radius: 50%;
    transform: translate(-50%, calc(-50% - 15px));
}

.keyhole::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    background-color: #3d464d;
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

.keyhole::after {
    content: "";
    position: absolute;
    bottom: -30px;
    left: 50%;
    width: 30px;
    height: 35px;
    background-color: inherit;
    transform: translateX(-50%);
}

            
          
!
            
              //DOM load event
window.addEventListener("DOMContentLoaded",	() => {

    //Check that page is not running in a CodePen preview iframe
    if (!document.body.hasAttribute('translate')) {

        //Set speech recognition
        window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;

        const recognition = new SpeechRecognition(),
              padlock = document.querySelector('.padlock'),
              openSound = document.querySelector('.padlock-open'),
              closeSound = document.querySelector('.padlock-close'),
              heardOutput = document.querySelector('.heard-output'),
              openPadlock = () => {
                  padlock.classList.add('unlock');
                  openSound.play();
              },
              closePadlock = () => {
                  padlock.classList.remove('unlock');
                  closeSound.play();
              };

        //Start speech recognition
        recognition.start();

        //Listen for when the user finishes talking
        recognition.addEventListener('result', e => {

            //Get transcript of user speech
            const transcript = e.results[0][0].transcript.toLowerCase().replace(/\s/g, '');

            //Output transcript
            heardOutput.textContent = transcript;

            //Check if transcript is valid
            if (transcript === 'unlock' && !padlock.classList.contains('unlock')) {
                openPadlock();
            } else {
                if (transcript === 'lock' && padlock.classList.contains('unlock')) {
                    closePadlock();
                }
            }
        });

        //Restart speech recognition after user has finished talking
        recognition.addEventListener('end', recognition.start);

        //Click padlock to open/close
        padlock.addEventListener('click', () => padlock.classList.contains('unlock') ? closePadlock() : openPadlock());
    }
});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console