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 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

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

              
                <main>
    <!-- ================== -->
    <!-- Music Player Element -->

    <section class="music-player">
        <div class="bg-list" id="bg-list">
            <img src="https://images.unsplash.com/photo-1526478806334-5fd488fcaabc?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1990&q=80" alt="Unsplash Photo" width="460">
            <img src="https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80" alt="Unsplash Photo" width="460">
            <img src="https://images.unsplash.com/photo-1510414842594-a61c69b5ae57?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80" alt="Unsplash Photo" width="460">
        </div>
        <div class="player-progress" id="player-progress">

        </div>
        <div class="player-content">
            <div class="music-info animation-info" id="music-info">
                <img id="song-img" src="https://scontent.fhkg1-1.fna.fbcdn.net/v/t1.0-9/93705390_2860720260715557_3411138733871726592_o.jpg?_nc_cat=102&_nc_sid=e3f864&_nc_ohc=GqIUJlcIEmUAX999eTg&_nc_ht=scontent.fhkg1-1.fna&oh=e07a5410813149065f4774514208cd4a&oe=5F4665FB" alt="Broken Elegance Picture" class="mv-img" width="50">
                <div class="text-info">
                    <h5 id="song-name">Pyres</h5>
                    <h6 id="song-author">Broken Elegance - 3:34</h6>
                </div>
            </div>
            <div class="control-panel">
                <button id="btn-love" class="btn-love" onclick="changeIcon()"><i id="love-icon" class="far fa-heart"></i></button>
                <button id="btn-back" class="btn-back" onclick="prevSong()" disabled><i id="back-icon" class="fas fa-fast-backward"></i></button>
                <button id="btn-play" class="btn-play" onclick="playAudio()" disabled><i id="play-icon" class="fas fa-play"></i></button>
                <button id="btn-next" class="btn-next" onclick="nextSong()" disabled><i id="next-icon" class="fas fa-fast-forward"></i></button>
                <button id="btn-stop" class="btn-stop" onclick="stopAudio()"><i id="stop-icon" class="fas fa-stop"></i></button>
            </div>
        </div>
    </section>
    <!-- Music Player Element -->
    <!-- ================== -->
</main>

<!-- UI Designer -->
<h6 class="designer">Designed by <a href="https://dribbble.com/shots/13898872-Music-player" target="_blank">Diego Valbuena</a> And Made by <a href="https://codepen.io/tin-fung-hk" target="_blank">Tin Fung</a></h6>
              
            
!

CSS

              
                :root {
    /* Font Color */
    --light-theme: #f4f2e2;
    
    /* Circle Width */
    --circle-diameter: 300px;

    /* Font Family */
    --fonts-style-x: 'neuzeit-grotesk', sans-serif;
    --fonts-style-y: 'neuzeit-grotesk', sans-serif;

    /* Font Weight */
    --light: 300;
    --regular: 400;
    --bold: 700;
    --black: 900;

}


/* ------------- */
/* Basic Setting */
/* ------------- */

html,
body {
    box-sizing: border-box;
    font-family: 'neuzeit-grotesk', sans-serif;
    font-weight: 300;
    font-style: normal;
    font-size: 1em;
    line-height: 1.5;
    color: #ffffffee;
    scroll-behavior: smooth;
}

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

main {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100vh;
    min-height: 400px;
    background-color: var(--light-theme);
}

::selection {
    color: #fff;
    background-color: var(--light-theme);
}


/* ------------- */
/* Content Style */
/* ------------- */

.music-player {
    position: relative;
    width: 360px;
    height: 180px;
    padding: 30px;
    margin: 20px;
    border-radius: 14px;
    overflow: hidden;
    font-family: 'neuzeit-grotesk', sans-serif;
    font-weight: 300;
    font-style: normal;
    font-size: 1em;
    line-height: 1.5;
    color: #ffffffee;
    background-color: #383415;
    box-shadow: 0 40px 120px #b8ab4844;
}

.music-player .bg-list {
    position: absolute;
    display: flex;
    flex-direction: column;
    top: 0;
    left: 0;
    width: 100%;
    height: calc(100% * 3);
    transition: 500ms;
}

.music-player .bg-list img {
    width: inherit;
    height: calc(100% / 3);
    object-fit: cover;
    object-position: center;
    opacity: .5;
}

.music-player .player-progress {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 100%;
    border-right: 1px solid #dddddd44;
    background-color: #44444444;
    transition: 300ms;
}

.music-player .player-content {
    position: relative;
    width: 100%;
    height: 100%;
    z-index: 100;
}

.music-player .music-info {
    position: absolute;
    display: flex;
    top: 0;
    left: 0;
    color: #ffffffdd;
}

.music-player .music-info .mv-img {
    width: 50px;
    height: 50px;
    object-position: center;
    object-fit: cover;
    border-radius: 8px;
}

.music-player .music-info .text-info {
    width: 200px;
    height: 50px;
    margin-left: 20px;
}

.music-player .control-panel {
    position: relative;
    display: flex;
    justify-content: space-around;
    align-items: center;
    top: 100%;
    transform: translateY(-100%);
    width: 100%;
    height: 50px;
    padding: 0 20px;
    border-radius: 8px;
    background-color: #ffffffee;
}

.music-player .control-panel button {
    border: none;
    outline: none;
    font-size: 1.125em;
    color: #2a3e38;
    background-color: #ffffff00;
}

.music-player .control-panel button i {
    cursor: pointer;
}

.music-player .control-panel .btn-love {
    color: #d96262;
}

.music-player .control-panel .btn-back {
    color: #2a3e38;
}

.music-player .control-panel .btn-play {
    color: #2a3e38;
}

.music-player .control-panel .btn-next {
    color: #2a3e38;
}

.music-player .control-panel .btn-stop {
    color: #99b9af;
}

.music-player .control-panel .btn-play i {
    font-size: 1.25em;
}

.music-player .control-panel button:disabled i {
    color: #99b9af;
}

.music-player h5 {
    font-size: 1.25em;
    font-weight: 700;
    letter-spacing: .5px;
    color: #ffffffdd;
    white-space: nowrap;
    margin-bottom: -5px;
}

.music-player h6 {
    font-size: .875em;
    font-weight: 300;
    color: #ffffffaa;
    white-space: nowrap;
}

.animation-popup {
    animation: Popup 300ms ease-in-out;
}

.animation-info {
    animation: InfoFadeIn 300ms ease-in-out;
}


/* ------------------ */
/* Interactive Effect */
/* ------------------ */

.music-player .control-panel button i:hover {
    opacity: .8;
}


/* --------- */
/* Animation */
/* --------- */

@keyframes Popup {
    0% {
        transform: scale(1);
    }
    10% {
        transform: scale(1.2);
    }
    55% {
        transform: scale(.8);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes InfoFadeIn {
    0% {
        top: 20px;
        opacity: 0;
    }
    100% {
        top: 0;
        opacity: 1;
    }
}


/* ----------- */
/* UI Designer */
/* ----------- */

.designer {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    font-weight: 400;
    color: #d3cb8a;
    letter-spacing: 1px;
    text-align: center;
    text-transform: uppercase;
    transition: 300ms;
}

.designer a {
    text-decoration: none;
    color: #6e6629;
}

body:hover .designer {
    opacity: 1;
}

              
            
!

JS

              
                // DOM Element
var loveIcon = document.getElementById("love-icon");
var playIcon = document.getElementById("play-icon");
var stopIcon = document.getElementById("stop-icon");
var prevIcon = document.getElementById("back-icon");
var nextIcon = document.getElementById("next-icon");
var playBtn = document.getElementById("btn-play");
var prevBtn = document.getElementById("btn-back");
var nextBtn = document.getElementById("btn-next");

var playerProgress = document.getElementById("player-progress");
var songName = document.getElementById("song-name");
var songAuthor = document.getElementById("song-author");
var songImg = document.getElementById("song-img");

// Element Content
var music;
var musicInfo = document.getElementById("music-info");
var bgList = document.getElementById("bg-list");

var musicList = {
    songItem1: {
        name: "Pyres",
        src: "https://drive.google.com/uc?id=14IXczkjUwJ7vB-_LDRhTRucANcHZpIl3&export=download",
        author: "Broken Elegance - 3:34",
        img: "https://scontent.fhkg1-1.fna.fbcdn.net/v/t1.0-9/93705390_2860720260715557_3411138733871726592_o.jpg?_nc_cat=102&_nc_sid=e3f864&_nc_ohc=GqIUJlcIEmUAX999eTg&_nc_ht=scontent.fhkg1-1.fna&oh=e07a5410813149065f4774514208cd4a&oe=5F4665FB",
        imgAlt: "Broken Elegance Picture"
    },
    songItem2: {
        name: "Tokyo Sunset",
        src: "https://drive.google.com/uc?id=1NF-yhigljC6XFEfb_NyuCs3CDzyMfe5H&export=download",
        author: "Erik Lund - 3:42",
        img: "https://y.gtimg.cn/music/photo_new/T001R300x300M0000030cy7e1EIBYa.jpg?max_age=2592000",
        imgAlt: "Erik Lund Picture"
    },
    songItem3: {
        name: "Beach",
        src: "https://drive.google.com/uc?id=1XaNKPqJzgymsVtgUoShLyEjaWMPwCM7i&export=download",
        author: "MBB - 2:02",
        img: "https://i1.sndcdn.com/artworks-000241642226-a9q7my-t500x500.jpg",
        imgAlt: "MBB Picture"
    }
};

var listItem = Object.values(musicList);
var listItemLength = listItem.length;

// Status
var loadStatus = 0;
var playerStatus = 0;
var loveStatus = 0;
var songLength = 0;
var songProgress;
var songItem = 1;
var canPlay = 0;

window.onload = function() {
    setAudio(songItem);
    console.log("onload");
}

function setAudio(x) {
    var itemSrc = Object.values(listItem[x - 1]);

    music = new Audio(itemSrc[1]);

    songName.innerHTML = itemSrc[0];
    songAuthor.innerHTML = itemSrc[2];
    songImg.setAttribute("src", itemSrc[3]);
    bgList.style.top = ((songItem - 1) * -100) + "%";

    // Restart Animation
    musicInfo.classList.remove("animation-info");
    void musicInfo.offsetWidth;
    musicInfo.classList.add("animation-info");

    console.log(music);

    music.onloadeddata = function() {
        canPlay = 1;
        playBtn.disabled = false;
        console.log("canPlay");
    }
}

function playAudio() {
    playerStatus = 1;
    playBtn.setAttribute("onclick", "pauseAudio()");
    playIcon.setAttribute("class", "fas fa-pause");
    stopIcon.style.color = "#2a3e38";

    if (canPlay == 1) {
        music.play();

        getSongLength();

        songProgress = setInterval(setLength, 30);

        enableBtn();
    } else {

    }
    
    restartAnimation(playIcon);
}

function pauseAudio() {
    music.pause();
    playerStatus = 0;
    playBtn.setAttribute("onclick", "playAudio()");
    playIcon.setAttribute("class", "fas fa-play");

    restartAnimation(playIcon);

    disableBtn();

    stopProgress();

    console.log("pause");
}

function stopAudio() {
    music.currentTime = 0;
    stopIcon.style.color = "#99b9af";

    restartAnimation(stopIcon);

    pauseAudio();
    setLength();

    console.log("stop");
}

function prevSong() {
    songItem -= 1;

    stopAudio();

    restartAnimation(prevIcon);

    if (songItem < 1) {
        songItem = listItemLength;
        setAudio(songItem);
    } else {
        setAudio(songItem);
    }

    disableBtn();

}

function nextSong() {
    songItem += 1;

    stopAudio();

    restartAnimation(nextIcon);

    if (songItem > listItemLength) {
        songItem = 1;
        setAudio(songItem);
    } else {
        setAudio(songItem);
    }

    disableBtn();

}

function getSongLength() {
    songlength = music.duration;

    console.log(songlength);
}

function setLength() {
    var timeTrack = music.currentTime;

    playerProgress.style.width = ((timeTrack * 100) / songlength) + "%";
}

function stopProgress() {
    clearInterval(songProgress);
}

function enableBtn() {
    prevBtn.disabled = false;
    nextBtn.disabled = false;

    console.log("enableBtn");
}

function disableBtn() {
    prevBtn.disabled = true;
    nextBtn.disabled = true;

    console.log("disableBtn");
}

function changeIcon() {

    if (loveStatus == 0) {
        loveIcon.setAttribute("class", "fas fa-heart");
        loveStatus = 1;
    } else if (loveStatus == 1) {
        loveIcon.setAttribute("class", "far fa-heart");
        loveStatus = 0;
    } else {
        loveStatus = 0;
    }

    restartAnimation(loveIcon);
}

function restartAnimation(icon) {
    // Restart Animation
    icon.classList.remove("animation-popup");
    void icon.offsetWidth;
    icon.classList.add("animation-popup");
}
              
            
!
999px

Console