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.

            
              <div class="player">
    <div class="vinyl"></div>
    <div class="cover">
        <div class="header">
            <div class="artist"><a href="#" target="_blank"></a></div>
            <div class="title"></div>
        </div>
        <div class="controls">
            <button class="transparent loop fi-loop"></button>
            <span>
                <button class="prev fi-previous"></button>
                <button class="play fi-play"></button>
                <button class="stop fi-stop"></button>
                <button class="next fi-next"></button>
            </span>
            <button class="transparent shuffle fi-shuffle"></button>
            <div class="progressbar">
                <div class="progress"></div>
            </div>
        </div>
    </div>
</div>
            
          
!
            
              $primary: #98c6c3; // daphne blue
$light: #f4f3ef; // artic white
$transparent: rgba(0,0,0,.8);

html, body { height: 100%; }
body{ 
    background: radial-gradient($light, $primary);
    overflow: hidden;
}

.player {
    position: absolute;
    top:50%; left:50%;
    height:260px; width:260px;
    margin: -130px 0 0 -130px;
    font-family: 'Roboto', sans-serif;
    color: $light;
    cursor: default;
    box-shadow: 0 3px 10px rgba(0,0,0,.4);
}

.vinyl {
    position: absolute;
    height: 98%; width: 98%;
    top: 1%; left: 51%;
    background: url('http://www.thebeatles.com/monovinyl/images/site/record.png') center;
    background-size: 280px 280px;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0,0,0,.3);
    pointer-events: none;
    transition: left .8s, -webkit-transform 1.5s;
  -webkit-transform: rotate(-45deg);
       -moz-transform: rotate(-90deg);
        -ms-transform: rotate(-90deg);
         -o-transform: rotate(-90deg);
            transform: rotate(-90deg);
}
.player.playing .vinyl {
    left: 1%;
    transition: all .8s;
    -webkit-transform: rotate(0);
       -moz-transform: rotate(0);
        -ms-transform: rotate(0);
         -o-transform: rotate(0);
            transform: rotate(0);
}

.cover {
    position: absolute;
    height:100%; width:100%;
    background-color: black;
    background-size: cover;
    background-position: center;
    overflow: hidden;
}

.header, .controls {
    background: $transparent;
    transition: all ease-out .3s;
}

.header {
    position: absolute;
    top: -40px;
    width:100%;
    padding: 5px;
    box-sizing: border-box;
    white-space: nowrap;
}
.header.show, 
.player:hover .header {
    top: 0px;
}

.artist, .title {
    line-height: 15px;
    text-align: center;
}
.artist {
    font-size: 13px;
    font-weight: 700;
}
.artist a {
    color: $light;
}
.title {
    font-size: 11px;
    font-weight: 300;
}

.controls {
    position: absolute;
    bottom: -40px;
    width: 100%;
    padding: 5px; 
    text-align: center;
    box-sizing: border-box;
}
.player:hover .controls {
    bottom: 0px;
}

.controls button {
    height: 30px; width: 30px;
    border: 0;
    cursor: pointer;
    font-size: 100%;
    color: $light;
    border-radius: 3px;
    box-shadow: 
        inset 1px 1px 0 rgba(255,255,255,.3),
        inset -1px -1px 0 rgba(0,0,0,.3);
    text-shadow: 0 1px 1px rgba(0,0,0,.3);
    background: linear-gradient($primary, darken($primary, 10%));
    transition: all .1s;
}
.controls button:active {
    background: linear-gradient(darken($primary, 10%), $primary);
}
.controls button:focus {
    outline: 0;
}

.controls button.transparent { 
    background: transparent;
    box-shadow: none;
    color: rgba(255,255,255,.3);
}
.controls button.active { color: $light; }
.controls button.loop { float: left; }
.controls button.shuffle { float: right; }

.progressbar {
    opacity: 0;
    position: absolute;
    bottom: 40px; left: 0;
    height: 5px;
    width: 100%;
    background: linear-gradient(
        darken($primary, 30%), 
        darken($primary, 25%),
        darken($primary, 30%));
    cursor: pointer;
    transition: opacity .2s;
}
.player.playing .progressbar {
    opacity: 1;
}

.progress {
    height: 100%;
    width: 0;
    background: $light;
    box-shadow: inset 0 0 1px darken($light, 15%);
}
            
          
!
            
              var music = [
    {
        title: 'Free Four',
        artist: 'Pink Floyd',
        artistWiki: 'http://en.wikipedia.org/wiki/Pink_floyd',
        album: 'Obscured by Clouds',
        cover: 'http://upload.wikimedia.org/wikipedia/en/e/ef/Pink_Floyd_-_Obscured_by_Clouds.jpg',
        length: '5000'
    },
    {
        title: 'Iron Tusk',
        artist: 'Mastodon',
        artistWiki: 'http://en.wikipedia.org/wiki/Mastodon_(band)',
        album: 'Leviathan',
        cover: 'http://upload.wikimedia.org/wikipedia/en/c/ca/Leviathan_special_edition_cover.jpg',
        length: '5000'
    },
    {
        title: 'I Want You (She\'s So Heavy)',
        artist: 'The Beatles',
        artistWiki: 'http://en.wikipedia.org/wiki/Beatles',
        album: 'Abbey Road',
        cover: 'http://upload.wikimedia.org/wikipedia/en/4/42/Beatles_-_Abbey_Road.jpg',
        length: '5000'
    }
]

var song_id = 0;
var song = music[0];
var titleInterval = null;
var timerStart = 0;
var timerPause = 0;

function init() {
    show();
    setTimeout(function() {
        showHeader();
        play();
    }, 1000);
}

function show() {
    song = music[song_id];
    $('.artist a').html(song.artist).attr('href', song.artistWiki);
    $('.title').html(song.title);
    $('.cover').css('background-image', 'url('+song.cover+')');
}

function showHeader() {
    $('.header').addClass('show');
    setTimeout(function() { $('.header').removeClass('show'); }, 2000);
}

function togglePlay() {
    if($('.player').hasClass('playing') && !$('.player').hasClass('paused')) pause();
    else play();
}

function play() {
    show();
    $('.player').removeClass('paused').addClass('playing');
    $('.controls .play').removeClass('fi-play').addClass('fi-pause');
    startProgress();
}

function pause() {
    $('.player').addClass('paused');
    $('.controls .play').removeClass('fi-pause').addClass('fi-play');
    pauseProgress();
}

function stop() {
    $('.player').removeClass('paused').removeClass('playing');
    $('.controls .play').removeClass('fi-pause').addClass('fi-play');
    stopProgress();
    initProgress();
    song_id = 0;
    show();
}

function prev() {
    if(song_id <= 0) song_id = 0;
    else song_id--;
    
    show();
    showHeader();
    stopProgress();
    initProgress();
    if($('.player').hasClass('playing') && !$('.player').hasClass('paused')) startProgress();
}

function next() {
    if(song_id >= music.length-1) {
        stop();
    }
    else {
        song_id++;
        show();
        showHeader();
        stopProgress();
        initProgress();
        if($('.player').hasClass('playing') && !$('.player').hasClass('paused')) startProgress();
    }
}

function initProgress() {
    $('.progress').css('width', '0');
}

function startProgress() {
    if(timerStart == 0) {
        timerStart = Date.now();
        var length = parseInt(song.length);
    }
    else var length = parseInt(song.length) - (timerPause - timerStart);
    
    $('.progress').animate({ width: '100%' }, length, 'linear', next);
}

function pauseProgress() {
    $('.progress').stop();
    timerPause = Date.now();
}

function stopProgress() {
    $('.progress').stop();
    timerStart = 0;
    timerPause = 0;
}

$('.play').click(function(){ togglePlay(); });
$('.stop').click(function(){ stop(); });
$('.prev').click(function(){ prev(); });
$('.next').click(function(){ next(); });
$('.loop, .shuffle').click(function(){ 
    $(this).toggleClass('active'); 
});

init();
            
          
!
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