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

              
                <form id="form">
        <label for="fav-animal-input" id="fav-animal-input-label">
            Describe penguins in 20 characters or less.
        </label>
        <br/>
        <div class="penguin-container">
            <div class="word-bubble"></div>
            <div class="penguin">
                <div class="penguin__tail"></div>
                <div class="penguin__feet"></div>
                <div class="penguin__body"></div>
                <div class="penguin__head"></div>
                <div class="penguin__wings">
                    <div class="penguin__wing--left"></div>
                    <div class="penguin__wing--right"></div>
                </div>
            </div>
        </div>
        <input type="text" id="fav-animal-input" class="textbox" maxLength="20" placeholder="type here" autocomplete="off"></input>
        <button class="btn-submit">Submit</button>
    </form>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Itim&display=swap');

:root {
    --input-width: 300px;
    --penguin-size: 50px;
    --penguin-black: black;
    --penguin-white: white;
    --penguin-orange: #FF6F00;
    --text-color: #000000;
    --button-color-1: #C7EFCF;
    --button-color-2: #78c087;
    --button-active-color-1: #86ffed;
    --button-active-color-2: #5ec0b1;
    --background-color-1: #C7EFCF;
    --background-color-2: #E3BAC6;
    --input-color: #86ffed;
}

body {
    height: 100vh;
    margin: 0;
    display: flex;
    background: linear-gradient(45deg, var(--background-color-1), var(--background-color-2));
    color: var(--text-color);
}

body, button, .textbox {
    font-family: 'Itim', cursive;
}

#form {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100vw;
}

button {
    padding: 8px 10px;
    margin: 20px;
    border-radius: 4px;
    border: none;
    background: var(--button-color-1);
    cursor: pointer;
    font-size: 1.2rem;
    box-shadow: inset -3px -5px var(--button-color-2), inset 3px 1px var(--button-color-2);
    color: var(--text-color);
}

button:hover {
    transform: translateY(-2px);
}

button:active {
    transform: translateY(5px);
}

button:hover,
button:focus {
    --button-color-1: var(--button-active-color-1);
    --button-color-2: var(--button-active-color-2);
}

.textbox {
    --padding: 10px;
    padding: var(--padding);
    width: calc(var(--input-width) - (2 * var(--padding)));
    resize: none;
    border-radius: 4px;
    text-align: center;
    letter-spacing: 1px;
    font-size: 1.5rem;
    border: 2px solid var(--text-color);
}

.textbox:focus {
    background: var(--input-color);
}

.penguin-container {
    width: var(--input-width);
}

.penguin {
    width: var(--penguin-size);
    height: var(--penguin-size);
}

.penguin * {
    position: absolute;
}

.penguin__body {
    width: 35px;
    height: 37px;
    background: var(--penguin-white);
    box-shadow: inset 0px 6px 0px 5px var(--penguin-black);
    border-radius: 50% 50% 35% 35%;
    transform: translate(5px, 10px);
}

.penguin__wings * {
    width: 22px;
    height: 6px;
    border-radius: 50%;
    background: var(--penguin-black);
}

.penguin__wing--left {
    transform: translate(-6px, 23px) rotate(-48deg);
}

.penguin__wing--right {
    transform: translate(29px, 23px) rotate(48deg);
}

.penguin__feet {
    width: 10px;
    height: 10px;
    background: var(--penguin-orange);
    border-radius: 0% 0% 50% 50%;
    box-shadow: 15px 0 var(--penguin-orange);
    transform: translate(10px, 40px);
}

.penguin__tail {
    width: 10px;
    height: 10px;
    background: var(--penguin-black);
    border-radius: 2px;
    transform: translate(3px, 33px) rotate(27deg);
}

.penguin__head {
    width: 20px;
    height: 15px;
    background: var(--penguin-black);
    border-radius: 50% 50% 0 0;
    transform: translate(13px, 0px);
}

.penguin__head::before {
    content: '';
    position: absolute;
    width: 4px;
    height: 4px;
    background: var(--penguin-white);
    border-radius: 50%;
    transform: translate(10px, 5px);
}

.penguin__head::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 5px;
    background: var(--penguin-orange);
    border-radius: 40% 50% 50% 40%;
    transform: translate(18px, 5px);
}

.word-bubble {
    --bubble-color: black;
    --font-color: white;
    transform: translateX(-10px);
    width: max-content;
    padding: 4px 8px;
    background: var(--bubble-color);
    border-radius: 2px;
    margin-bottom: 15px;
    color: var(--font-color);
    letter-spacing: 1px;
}

.word-bubble::before {
    content: '';
    background: linear-gradient(-45deg, var(--bubble-color) 0 50%,transparent 50% 100%);
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    transform: translate(10px, 15px) rotate(45deg);
}

#fav-animal-input-label {
    font-size: 2rem;
    height: 8rem;
    margin: 20px 20px 30px;
    text-align: center;
    display: flex;
    align-items: center;
}

              
            
!

JS

              
                const jokeArr = [
        {question: "What do penguins like to eat?", answer: "Brrrrritos"},
        {question: "What's a penguin's favourite relative?", answer: "Aunt Arctica"},
        {question: "What do penguins wear on their heads?", answer: "Ice caps"},
        {question: "What kind of fish do penguins catch at night?", answer: "Starfish"},
        {question: "What's a penguin's favourite fast food?", answer: "Ice-burgers"},
    ];
    const minWordWarningArr = [
        "You gotta say something!",
        "Don't leave me hanging!",
        "Type 'penguins are cool!!!'",
        "Type 'penguins are awesome'",
        "Type 'penguins are amazing'",
    ];
    const textBoxEl = document.querySelector('.textbox');
    const formEl = document.querySelector('#form');
    const wordCountEl = document.querySelector('.word-bubble');
    const inputLabelEl = document.querySelector('#fav-animal-input-label');

    const textboxMaxLength = textBoxEl.maxLength;
    const textboxWidth = textBoxEl.getBoundingClientRect()['width'];
    const penguinWidth = document.querySelector('.penguin').getBoundingClientRect()['width'];
    const penguinMaxOffsetX = textboxWidth - penguinWidth;
    const penguinAnimDur = 0.2;
    let wordCount = 0;

    function getRandomJoke() {
        return jokeArr[Math.floor(Math.random() * jokeArr.length)];
    }

    function getMinWordWarning() {
        return minWordWarningArr[Math.floor(Math.random() * minWordWarningArr.length)];
    }

    function setWordCountLabel(text) {
        wordCountEl.innerHTML = text;
    }

    function handleNoWordCount() {
        gsap.timeline({ defaults: { duration: penguinAnimDur } })
            // --- textbox jiggle
            .to('#fav-animal-input', { x: -4, duration: penguinAnimDur / 4 })
            .to('#fav-animal-input', { x: 4,  duration: penguinAnimDur / 4 })
            .to('#fav-animal-input', { x: -4, duration: penguinAnimDur / 4 })
            .to('#fav-animal-input', { x: 4,  duration: penguinAnimDur / 4 })
            // --- word count reappear
            .to('.word-bubble', { y: 30, opacity: 0, duration: penguinAnimDur / 2 })
            .to('.word-bubble', { y: 0,  opacity: 1, duration: penguinAnimDur / 2 })
            // --- penguin flail
            .to('.penguin__wing--left',  { y: 17, rotate: -18 })
            .to('.penguin__wing--right', { y: 17, rotate: 18 }, `-=${penguinAnimDur}`)
            .to('.penguin__wing--left',  { y: 23, rotate: -48 })
            .to('.penguin__wing--right', { y: 23, rotate: 48 }, `-=${penguinAnimDur}`)
            .to('.penguin__wing--left',  { y: 17, rotate: -18 })
            .to('.penguin__wing--right', { y: 17, rotate: 18 }, `-=${penguinAnimDur}`)
            .to('.penguin__wing--left',  { y: 23, rotate: -48 })
            .to('.penguin__wing--right', { y: 23, rotate: 48 }, `-=${penguinAnimDur}`)
            setTimeout( () => wordCountEl.innerHTML = getMinWordWarning(), penguinAnimDur * 1500 );
    }

    function revealJokeAnim() {
        const inputTl = gsap.timeline({ defaults: { duration: penguinAnimDur } });
        const penguinTl = gsap.timeline({ defaults: { duration: penguinAnimDur } });
        const {question, answer} = getRandomJoke();

        inputTl
        .to('.btn-submit',              { y: -10 })
        .to('.btn-submit',              { y: 30, opacity: 0 })
        .to('#fav-animal-input',        { y: -10 })
        .to('#fav-animal-input',        { y: 30, opacity: 0 })
        .to('.btn-submit',              { visibility: 'hidden' }, `-=${penguinAnimDur * 2}`)
        .to('#fav-animal-input-label',  { y: -10 })
        .to('#fav-animal-input-label',  { y: 30, opacity: 0 })
        .to('#fav-animal-input',        { visibility: 'hidden' }, `-=${penguinAnimDur * 2}`)
        .to('#fav-animal-input-label',  { y: 0, opacity: 1 })

        penguinTl
        .to('.word-bubble', { delay: penguinAnimDur, y: -10 })
        .to('.word-bubble', { y: 30, opacity: 0 })
        .to('.word-bubble', { y: 30, opacity: 0 })
        .to('.word-bubble', { x: penguinMaxOffsetX / 2 })
        .to('.penguin',     { x: penguinMaxOffsetX / 2 }, `-=${penguinAnimDur}`)
        // -------- walk 1 --------
        .to('.penguin__body', {
            borderRadius: '50px 50px 35px 35px',
            width: 35,
            height: 37,
            y: 10,
            boxShadow: 'inset 0px 6px 0px 5px black',
            rotate: 10,
            scale: 1.2
        })
        .to('.penguin__head', {
            x: 18,
            y: -5,
            rotate: 10,
            scale: 1.2
        }, `-=${penguinAnimDur}`)
        .to('.penguin__wing--left', {
            x: -9,
            y: 15,
            rotate: -16,
            scale: 1.2
        }, `-=${penguinAnimDur}`)
        .to('.penguin__wing--right', {
            x: 32,
            y: 23,
            rotate: 40,
            scale: 1.2
        }, `-=${penguinAnimDur}`)
        .to('.penguin__feet', {
            x: 6,
            y: 45,
            rotate: 0,
            boxShadow: '15px 0 #FF6F00',
            scale: 1.2
        }, `-=${penguinAnimDur}`)
        .to('.penguin__tail', {
            x: -3,
            y: 31,
            rotate: 37,
            scale: 1.2
        }, `-=${penguinAnimDur}`)
        // -------- walk 2 --------
        .to('.penguin__body', {
            rotate: -10,
            scale: 1.4
        })
        .to('.penguin__head', {
            x: 7,
            y: -9,
            rotate: -10,
            scale: 1.4
        }, `-=${penguinAnimDur}`)
        .to('.penguin__wing--left', {
            x: -13,
            y: 23,
            rotate: -60,
            scale: 1.4
        }, `-=${penguinAnimDur}`)
        .to('.penguin__wing--right', {
            x: 33,
            y: 14,
            rotate: 40,
            scale: 1.4
        }, `-=${penguinAnimDur}`)
        .to('.penguin__feet', {
            x: 10,
            y: 48,
            scale: 1.4
        }, `-=${penguinAnimDur}`)
        .to('.penguin__tail', {
            x: -1,
            y: 37,
            rotate: 33,
            scale: 1.4
        }, `-=${penguinAnimDur}`)
        // -------- walk 3 --------
        .to('.penguin__body', {
            rotate: 10,
            scale: 1.6
        })
        .to('.penguin__head', {
            x: 21,
            y: -12,
            rotate: 10,
            scale: 1.6
        }, `-=${penguinAnimDur}`)
        .to('.penguin__wing--left', {
            x: -17,
            y: 11,
            rotate: -28,
            scale: 1.6
        }, `-=${penguinAnimDur}`)
        .to('.penguin__wing--right', {
            x: 39,
            y: 17,
            rotate: 40,
            scale: 1.6
        }, `-=${penguinAnimDur}`)
        .to('.penguin__feet', {
            x: 1,
            y: 51,
            scale: 1.6
        }, `-=${penguinAnimDur}`)
        .to('.penguin__tail', {
            x: -10,
            y: 30,
            rotate: 46,
            scale: 1.6
        }, `-=${penguinAnimDur}`)
        // -------- walk 4 --------
        .to('.penguin__body', {
            rotate: -10,
            scale: 1.8
        })
        .to('.penguin__head', {
            x: 5,
            y: -19,
            rotate: -10,
            scale: 1.8
        }, `-=${penguinAnimDur}`)
        .to('.penguin__wing--left', {
            x: -23,
            y: 27,
            rotate: -61,
            scale: 1.8
        }, `-=${penguinAnimDur}`)
        .to('.penguin__wing--right', {
            x: 40,
            y: 11,
            rotate: 40,
            scale: 1.8
        }, `-=${penguinAnimDur}`)
        .to('.penguin__feet', {
            x: 9,
            y: 55,
            scale: 1.8
        }, `-=${penguinAnimDur}`)
        .to('.penguin__tail', {
            x: -7,
            y: 41,
            rotate: 30,
            scale: 1.8
        }, `-=${penguinAnimDur}`)
        // -------- walk 5 --------
        .to('.penguin__body', {
            rotate: 0,
            scale: 2
        })
        .to('.penguin__head', {
            x: 12,
            y: -24,
            rotate: 0,
            scale: 2
        }, `-=${penguinAnimDur}`)
        .to('.penguin__wing--left', {
            x: -24,
            y: 17,
            rotate: -48,
            scale: 2
        }, `-=${penguinAnimDur}`)
        .to('.penguin__wing--right', {
            x: 44,
            y: 12,
            rotate: 43,
            scale: 2
        }, `-=${penguinAnimDur}`)
        .to('.penguin__feet', {
            x: 3,
            y: 60,
            scale: 2
        }, `-=${penguinAnimDur}`)
        .to('.penguin__tail', {
            x: -12,
            y: 41,
            rotate: 27,
            scale: 2
        }, `-=${penguinAnimDur}`)
        // ---- word bubble reappear
        .to('.word-bubble', {
            y: -35,
            opacity: 1,
        })
        .to('.penguin__wing--left', {
            y: 7, rotate: -18,
        }, `-=${penguinAnimDur}`)
        .to('.penguin__wing--right', {
            y: 7, rotate: 13,
        }, `-=${penguinAnimDur}`)
        .to('.penguin__wing--left', {
            y: 14, rotate: -48,
        })
        .to('.penguin__wing--right', {
            y: 12, rotate: 43,
        },`-=${penguinAnimDur}`)
        .to('.penguin__wing--left', {
            y: 7, rotate: -18,
        })
        .to('.penguin__wing--right', {
            y: 7, rotate: 13,
        }, `-=${penguinAnimDur}`)
        .to('.penguin__wing--left', {
            y: 14, rotate: -48,
        })
        .to('.penguin__wing--right', {
            y: 12, rotate: 43,
        },`-=${penguinAnimDur}`);

        setTimeout( () => {
            inputLabelEl.innerHTML = question;
            wordCountEl.innerHTML = answer;
        },  penguinAnimDur * 6000 );
    }

    
    formEl.addEventListener('submit', e => {
        e.preventDefault();
        
        if (!wordCount){
            handleNoWordCount();
        } else {
            revealJokeAnim();
        }
    });

    textBoxEl.addEventListener('keyup', e => {
        if (wordCount === e.target.value.length) {
            return;
        }

        wordCount = e.target.value.length;
        setWordCountLabel(`${textboxMaxLength - wordCount} chars left`);
        
        const anim = gsap.timeline({ defaults: { duration: penguinAnimDur } });
        const penguinOffsetX = wordCount / textboxMaxLength * penguinMaxOffsetX;

        anim.to('.penguin', {
            x: penguinOffsetX,
        }).to('.word-bubble', {
            x: penguinOffsetX,
        }, `-=${penguinAnimDur}`);

        switch(wordCount) {
            case 0:
            case textboxMaxLength:
                setWordCountLabel(!wordCount ? `Start typing!` : `Phew!`);
                anim
                .to('.penguin__body', {
                    borderRadius: '50px 50px 35px 35px',
                    width: 35,
                    height: 37,
                    y: 10,
                    boxShadow: 'inset 0px 6px 0px 5px black',
                })
                .to('.penguin__head', {
                    x: 13,
                    y: 0,
                    rotate: 0
                }, `-=${penguinAnimDur}`)
                .to('.penguin__wing--right', {
                    x: 29,
                    y: 23,
                }, `-=${penguinAnimDur}`)
                .to('.penguin__wing--left', {
                    x: -6,
                    y: 23,
                    rotate: -48
                }, `-=${penguinAnimDur}`)
                .to('.penguin__feet', {
                    x: 10,
                    y: 40,
                    rotate: 0,
                    boxShadow: '15px 0 #f5b23a'
                }, `-=${penguinAnimDur}`)
                .to('.penguin__tail', {
                    x: 3,
                    y: 33,
                    rotate: 27,
                }, `-=${penguinAnimDur}`);
                break;
            default:
                anim.to('.penguin__body', {
                    borderRadius: '50px 50px 20px 20px',
                    width: 38,
                    height: 26,
                    y: 24,
                    boxShadow: 'inset 0px 11px 0px 5px black',
                })
                .to('.penguin__head', {
                    x: 28,
                    y: 20,
                    rotate: wordCount%2 > 0 ? 30 : 40,
                }, `-=${penguinAnimDur}`)
                .to('.penguin__wing--right', {
                    x: 18,
                    y: 31,
                }, `-=${penguinAnimDur}`)
                .to('.penguin__wing--left', {
                    x: 13,
                    y: 38,
                    rotate: wordCount%2 > 0 ? -48 : -117
                }, `-=${penguinAnimDur}`)
                .to('.penguin__feet', {
                    x: -1,
                    y: 40,
                    rotate: 85,
                    boxShadow: 'none'
                }, `-=${penguinAnimDur}`)
                .to('.penguin__tail', {
                    x: 4,
                    y: 29,
                    rotate: wordCount%2 > 0 ? -10 : -20,
                }, `-=${penguinAnimDur}`);
                break;
        }
    });

    setWordCountLabel(`And I may tell you a joke!`);
              
            
!
999px

Console