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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <audio id="music" preload="true">
  <source src="http://mortensondigital.com/wp-content/uploads/2016/07/mogwai.mp3">
			<source src="http://mortensondigital.com/wp-content/uploads/2016/07/mogwai.ogg">
	</audio>

<div class="main">
  <div id="draggable" class="ui-widget-content">

    <div id="musicCont" class="flex-container settle">
      <div id="handle">
        <ul>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
        </ul>
      </div>
      <div id="artistNameAlbum">
        <p>Mogwai | Kappa</p>
      </div>
      <div id="albumCont" class="flex-item album flex-container">
        <img id="currentAlbum" class="flex-item" src="http://cache.swdlive.com/image/test/resize_1375300602.jpg">
      </div>
      <div id="audioplayer">


        <svg id="playButton" class="button" onclick="play()" x="0px" y="0px" width="4.5px" height="6.9px" viewBox="0 0 4.5 6.9" style="enable-background:new 0 0 4.5 6.9;">
  <polyline class="button" points="0.6,0.3 3.9,3.4 0.6,6.6 "/>
  </svg>


        <svg id="pauseButton" class="button" onclick="pause()" x="0px" y="0px" width="4.5px" height="6.9px" viewBox="0 0 4.5 6.9" style="enable-background:new 0 0 4.5 6.9;">
    <g>
      <line class="st0" x1="0.4" y1="0.1" x2="0.4" y2="6.8"/>
      <line class="st0" x1="4.1" y1="0.1" x2="4.1" y2="6.8"/>
    </g>
  </svg>
        <div id="timeline">
          <div id="playhead"></div>
        </div>
      </div>
    </div>
    <div id="sliderCont" class="flex-item">
      <div id="slider">
        <span></span>
      </div>
    </div>
  </div>
</div>

<div class="bgText">
  <h1>Music Player is operational. 
  <br>You can drag the player with the dots on click.<br>
  Have fun!</h1>
</div>
            
          
!
            
              html {
  background-color: #272733;
}

.main {
  margin-left: 60%;
  margin-top: 2%;
}

.album {
  margin-bottom: 25px;
}

#musicCont {
  background-color: #044154;
  position: absolute;
  z-index: 1;
  width: 400px;
  box-shadow: 0px 5px 5px 5px rgba(0, 0, 0, 0.2);
  border-bottom: 4px solid #3594BA;
}

.lift {
  animation: lift 350ms forwards;
}

@keyframes lift {
  0% {
    box-shadow: 0px 5px 5px 5px rgba(0, 0, 0, 0.2);
    transform: scale(1);
    transform: rotate(0deg);
  }
  100% {
    box-shadow: 0px 25px 5px 9px rgba(0, 0, 0, 0.1);
    transform: scale(1.03);
    transform: rotate(.5deg);
  }
}

.settle {
  animation: settle 200ms forwards;
}

@keyframes settle {
  0% {
    box-shadow: 0px 25px 5px 9px rgba(0, 0, 0, 0.1);
    transform: scale(1.03);
    transform: rotate(.5deg);
  }
  100% {
    box-shadow: 0px 5px 5px 5px rgba(0, 0, 0, 0.2);
    transform: scale(1);
    transform: rotate(0deg);
  }
}

.flex-container {
  list-style: none;
  display: flex;
  -webkit-flex-flow: row wrap;
  justify-content: space-around;
}

.flex-item {
  padding-bottom: 20px;
  width: 300px;
  height: 300px;
  margin-top: 30px;
  text-align: center;
}

#audioplayer {
  width: 300px;
  height: 60px;
}

.button {
  height: 35px;
  width: 35px;
  border: none;
  background-size: 50% 50%;
  background-repeat: no-repeat;
  background-position: center;
  float: left;
  outline: none;
}

#timeline {
  width: 240px;
  height: 2px;
  margin-right: 10px;
  margin-top: 20px;
  float: right;
  border-radius: 15px;
  background: #DBE3E3;
}

#playhead {
  width: 4px;
  height: 10px;
  margin-top: -4px;
  background: #fff;
  cursor: pointer;
}

#playButton,
#pauseButton {
  width: 10px;
  margin-top: 4px;
  margin-left: 10px;
  fill: none;
  stroke: #ffffff;
  stroke-width: 0.5;
  stroke-miterlimit: 10;
  cursor: pointer;
}

.button:hover {
  animation: bounce 500ms alternate;
}

@keyframes bounce {
  0% {
    transform: scale(1);
  }
  100% {
    transform: scale(1.2);
  }
}

#artistNameAlbum {
  display: inline-block;
  position: absolute;
  left: 140px;
  padding: 10px;
  color: white;
  font-family: Helvetica;
  font-weight: 300;
  font-size: 14px;
  margin-top: 0px;
  margin-bottom: 0px;
}

.ui-widget-content {
  width: 400px;
  height: 400px;
  border: none;
  background-color: rgba(0, 0, 0, 0);
}

#handle {
  position: absolute;
  display: inline-block;
  cursor: all-scroll;
  left: 190px;
  top: 415px;
  margin: 0px;
  padding: 0px;
}

li {
  list-style: none;
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 6px;
  background-color: #1D6B87;
}

ul {
  margin: 0px;
  padding: 0px;
}

h1{
  position: relative;
  top: -438px;
  left: 15%;
  font-family: Helvetica;
  color: rgba(29, 107, 135, .2)
}

.bgText{
  width: 54%;
  z-index: -2;
  font-size: 22px;
}
            
          
!
            
              var music = document.getElementById('music');
var duration;
var playButton = document.getElementById('playButton');
var pauseButton = document.getElementById('pauseButton');
var playhead = document.getElementById('playhead');
var timeline = document.getElementById('timeline');
var timelineWidth = timeline.offsetWidth - playhead.offsetWidth;

music.addEventListener("timeupdate", timeUpdate, false);

timeline.addEventListener("click", function(event) {
  moveplayhead(event);
  music.currentTime = duration * clickPercent(event);
}, false);

function clickPercent(e) {
  console.log(e);
  return (e.pageX - timeline.offsetLeft) / timelineWidth;
}

playhead.addEventListener('mousedown', mouseDown, false);
window.addEventListener('mouseup', mouseUp, false);

var onplayhead = false;

function mouseDown() {
  onplayhead = true;
  window.addEventListener('mousemove', moveplayhead, true);
  music.removeEventListener('timeupdate', timeUpdate, false);
}

function mouseUp(e) {
  if (onplayhead == true) {
    moveplayhead(e);
    window.removeEventListener('mousemove', moveplayhead, true);
    music.currentTime = duration * clickPercent(e);
    music.addEventListener('timeupdate', timeUpdate, false);
  }
  onplayhead = false;
}

function moveplayhead(e) {
  var newMargLeft = e.pageX - timeline.offsetLeft;
  if (newMargLeft >= 0 && newMargLeft <= timelineWidth) {
    playhead.style.marginLeft = newMargLeft + "px";
  }
  if (newMargLeft < 0) {
    playhead.style.marginLeft = "0px";
  }
  if (newMargLeft > timelineWidth) {
    playhead.style.marginLeft = timelineWidth + "px";
  }
}

function timeUpdate() {
  var playPercent = timelineWidth * (music.currentTime / duration);
  playhead.style.marginLeft = playPercent + "px";
}

function play() {
  if (music.paused) {
    music.play();
  }
}

function pause() {
  if (music.play) {
    music.pause();
  }
}

music.addEventListener("canplaythrough", function() {
  duration = music.duration;
}, false);

$("#draggable").draggable({
  handle: "#handle"
});

$(function() {
  $("#draggable").draggable();
});

$("#handle").mousedown(function() {
  $("#musicCont").removeClass("settle");
  $("#musicCont").addClass("lift");
});

$("#handle").mouseup(function() {
  $("#musicCont").removeClass("lift");
  $("#musicCont").addClass("settle");
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console