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

              
                <div class="container">
    <div class="buff-jambox">
        <div class="jambox">
            <div class="speaker top-left"></div>
            <div class="speaker top-right"></div>
            <div class="speaker bottom-left"></div>
            <div class="speaker bottom-right"></div>
        </div>
        <div class="arms">
            <div class="arm left-arm">
                <div class="bicep left-bicep"></div>
                <div class="forearm left-forearm"></div>
            </div>
            <div class="arm right-arm">
                <div class="bicep right-bicep"></div>
                <div class="forearm right-forearm"></div>
            </div>
        </div>
    </div>
    <div class="tracks">
        <h2 class="title">Tracks</h2>
        <a class="track" title="Jawbreaker - Do You Still Hate Me?" data-genre="rock" data-track="https://s3-us-west-2.amazonaws.com/s.cdpn.io/59639/rock.m4a"></a>
        <a class="track" title="Judas Priest - Painkiller" data-genre="metal" data-track="https://s3-us-west-2.amazonaws.com/s.cdpn.io/59639/metal.m4a"></a>
        <a class="track" title="Stevie Wonder - For Once In My Life" data-genre="soul" data-track="https://s3-us-west-2.amazonaws.com/s.cdpn.io/59639/soul.m4a"></a>
    </div>
</div>
              
            
!

CSS

              
                html,
body {
    height: 100%;
}

body {
    background: var(--sb-white);
    font-size: 16px;
    letter-spacing: .15em;
    text-transform: uppercase;
}

.container {
    height: 320px;
    margin: -160px auto 0;
    padding: 0;
    position: relative;
    top: 50%;
    width: 500px;
}

.tracks {
    height: 45px;
    padding: 30px 0;
    text-align: center;
    
    .title {
        margin-bottom: 5px;
        
        &:before,
        &:after {
            content: ' - '
        }
    }
    
    .track {
        background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/59639/buff-jambox.png') no-repeat -360px -450px;
        cursor: pointer;
        display: inline-block;
        height: 65px;
        margin: 0 0 30px;
        width: 100px;
        transform: scale(.8);
        transition: transform .2s ease-out;
        
        &:nth-child(2) {
            background-position: -360px -525px;
        }
        
        &:nth-child(3) {
            background-position: -360px -600px;
        }
        
        &:hover {
            transform: scale(1);
        }
        
        &:active {
            transform: scale(.95);
            transition: none;
        }
    }
}

.buff-jambox {
    height: 229px;
    margin: 0 auto;
    position: relative;
    width: 342px;
    
    .jambox {
        background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/59639/buff-jambox.png') no-repeat 0 0;
        height: 100%;
        left: 0;
        position: absolute;
        top: 0;
        width: 100%;
        z-index: 2;
    }
    
    .speaker {
        background-image: inherit;
        position: absolute;
        
        &.top-left {
            background-position: -360px 0;
            height: 47px;
            left: 8px;
            top: 44px;
            width: 47px;
        }

        &.top-right {
            background-position: -360px -70px;
            height: 47px;
            left: 280px;
            top: 43px;
            width: 47px;
        }

        &.bottom-left {
            background-position: -360px -140px;
            height: 108px;
            left: 8px;
            top: 102px;
            width: 108px;
        }

        &.bottom-right {
            background-position: -360px -270px;
            height: 107px;
            left: 221px;
            top: 102px;
            width: 107px;
        }
    }
    
    .arms {
        left: 5px;
        position: absolute;
        top: 80px;
        width: 325px;
        z-index: 1;
    }
    
    .arm {
        height: 87px;
        position: absolute;
        width: 120px;
        
        &.left-arm {
            right: 100%;
            animation: flex-left 1.5s ease-in-out 0s infinite alternate;
            transform-origin: 120px 71px;
        }
        
        &.right-arm {
            left: 100%;
            transform-origin: 0 71px;
            animation: flex-right 2s ease-in-out 0s infinite alternate;
        }
    }
    
    .bicep {
        background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/59639/buff-jambox.png') no-repeat;
        height: 100%;
        left: 0;
        position: absolute;
        top: 0;
        width: 100%;
        z-index: 2;
        
        &.left-bicep {
            background-position: -475px -165px;
        }

        &.right-bicep {
            background-position: -600px -165px;
        }
    }
    
    .forearm {
        background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/59639/buff-jambox.png') no-repeat;
        bottom: 22px;
        height: 161px;
        position: absolute;
        width: 106px;
        z-index: 1;
        
        &.left-forearm {
            background-position: -475px 0;
            left: 0;
            transform-origin: 0 100%;
            animation: flex-left 2s ease-in-out 0s infinite alternate;
        }
        
        &.right-forearm {
            background-position: -585px 0;
            right: 0;
            transform-origin: 100% 100%;
            animation: flex-right 1.5s ease-in-out 0s infinite alternate;
        }
    }
    
    &.playing {
        .jambox {
            background-position: 0 -462px;
        }
        
        .speaker {
            animation: bump-it .25s ease-in-out 0s infinite alternate;
        }
        
        .left-arm {
            animation: pump-left .25s ease-in-out 0s infinite alternate;
        }
        
        .right-arm {
            animation: pump-right .25s ease-in-out 0s infinite alternate;
        }
    }
    
    &[data-genre="metal"] {
        .left-arm,
        .right-arm {
            animation-duration: .15s;
        }
        
        .forearm.left-forearm {
            background-position: -695px 0;
        }
        
        .forearm.right-forearm {
            background-position: -805px 0;
            height: 301px;
            right: -23px;
            width: 470px;
        }
    }
    
    &[data-genre="rock"] {
        .bicep.left-bicep {
            background-position: -475px -260px;
        }
        
        .bicep.right-bicep {
            background-position: -600px -260px;
        }
    }
    
    &[data-genre="soul"] {
        .left-arm,
        .right-arm {
            animation-duration: .5s;
        }
        
        .bicep.left-bicep {
            background-position: -475px -350px;
            height: 97px;
            width: 123px;
        }
        
        .bicep.right-bicep {
            background-position: -602px -350px;
            height: 97px;
            width: 123px;
        }
        
        .forearm.left-forearm {
            background-position: -745px -305px;
            bottom: 18px;
            height: 170px;
            left: -2px;
            width: 142px;
        }
        
        .forearm.right-forearm {
            background-position: -905px -305px;
            bottom: 19px;
            height: 165px;
            right: -4px;
            width: 112px;
        }
    }
}

@keyframes bump-it {
    0% { 
        transform: scale(1); 
    }
    100% { 
        transform: scale(1.05); 
    }
}

@keyframes flex-left {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(4deg);
    }
}

@keyframes flex-right {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(-5deg);
    }
}

@keyframes pump-left {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(15deg);
    }
}

@keyframes pump-right {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(-15deg);
    }
}
              
            
!

JS

              
                var $jambox = $('.buff-jambox');
var $tracks = $('.track');
var audio = document.createElement('audio');

// player setup
audio.autoplay = false;
audio.loop = true;
audio.preload = 'auto';
audio.volume = 0;

// track click
$tracks.on('click', function(e) {
    e.preventDefault();

    var $target = $(e.currentTarget);
    var data = $target.data();
    
    if ($jambox.attr('data-genre') === data.genre) {
        pauseTrack();
        return;
    }

    audio.src = data.track;
    playTrack();

    $jambox.attr('data-genre', data.genre);
});

// stop music
$jambox.on('click', function(e) {
    e.preventDefault();

    if (audio.src) {
        audio.paused ? playTrack() : pauseTrack();
    }
});

// play
function playTrack() {
    audio.play();

    $jambox.addClass('playing');
    $(audio).animate({
        volume: 0.5
    }, 1000);
};

// pause
function pauseTrack() {
    audio.pause();
    audio.volume = 0;
    $jambox.removeClass('playing').attr('data-genre', '');
};
              
            
!
999px

Console