HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div id="player">
<div class="circle" id="circle-cont">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px"
viewBox="0 0 500 500">
<path id="song-time" fill="none" d="M250,5c135.3,0,245,109.7,245,245S385.3,495,250,495S5,385.3,5,250C5,116.2,112.2,7.5,245.4,5
h5.3"/>
</svg>
<div id="song-content">
<audio id="audio-player"></audio>
<span id="artist">Artist</span>
<span id="song">Song Title</span>
</div>
<div id="pause"></div>
</div>
<div id="playlist">
<div id="scrollbar">
<div id="bar"></div>
<div id="marker"></div>
</div>
<ul></ul>
</div>
</div>
<div id="contact">
<p id="twitter"><i class="fa fa-twitter fa-lg"></i> twaffles</p>
<p id="codepen"><i class="fa fa-codepen fa-lg"></i> acjdesigns</p>
</div>
@import url(https://fonts.googleapis.com/css?family=Cabin:400,700);
$tan: #E6E3DA;
$orange: #F78A52;
$ltorg: #F3C56F;
$yellow: #FEFAD7;
@each $num, $height1, $height2, $height3 in (1, 7px, 2px, 15px), (2, 5px, 10px, 15px), (3, 15px, 5px, 10px){
@keyframes waves#{$num}{
0%{
height: $height1;
margin-top: -#{$height1};
}
10%{
height: $height2;
margin-top: -#{$height2};
}
20%{
height: $height3;
margin-top: -#{$height3};
}
30%{
height: $height1;
margin-top: -#{$height1};
}
40%{
height: $height2;
margin-top: -#{$height2};
}
50%{
height: $height1;
margin-top: -#{$height1};
}
60%{
height: $height3;
margin-top: -#{$height3};
}
70%{
height: $height2;
margin-top: -#{$height2};
}
80%{
height: $height3;
margin-top: -#{$height3};
}
90%{
height: $height1;
margin-top: -#{$height1};
}
}
@-webkit-keyframes waves#{$num}{
0%{
height: $height1;
margin-top: -#{$height1};
}
10%{
height: $height2;
margin-top: -#{$height2};
}
20%{
height: $height3;
margin-top: -#{$height3};
}
30%{
height: $height1;
margin-top: -#{$height1};
}
40%{
height: $height3;
margin-top: -#{$height3};
}
50%{
height: $height2;
margin-top: -#{$height2};
}
60%{
height: $height1;
margin-top: -#{$height1};
}
70%{
height: $height3;
margin-top: -#{$height3};
}
80%{
height: $height1;
margin-top: -#{$height1};
}
90%{
height: $height2;
margin-top: -#{$height2};
}
100%{
height: $height1;
margin-top: -#{$height1};
}
}
}
*{
font-family: 'Cabin', sans-serif;
}
html,body{
height: 100%;
background: lighten($tan, 3%);
margin: 0;
overflow: hidden;
}
body{
&:before{
content: ' ';
display: block;
position: absolute;
width: 0;
height: 0;
right: 0;
bottom: 0;
border-top: 0vw solid transparent;
border-left: 25vw solid transparent;
border-bottom: 150vh solid rgba(darken($tan, 10%), 0.5);
}
&:after{
content: ' ';
display: block;
position: absolute;
width: 0;
height: 0;
right: 0;
top: 0;
border-bottom: 0vw solid transparent;
border-left: 95vw solid transparent;
border-top: 82vh solid rgba(darken($tan, 10%), 0.5);
}
}
#player{
width: 600px;
position: relative;
height: 258px;
overflow: hidden;
left: 50%;
top: 50%;
transform: translateX(-50%) translateY(-50%);
z-index: 3;
}
.circle{
border-radius: 50%;
}
#circle-cont{
border: 4px solid $orange;
width: 250px;
height: 250px;
background: $tan;
position: absolute;
z-index: 3;
svg{
z-index: 2;
position: absolute;
#song-time{
stroke: $ltorg;
stroke-width: 9.5px;
stroke-dasharray: 2000;
stroke-dashoffset: 2000;
}
}
#song-content{
width: 85%;
height: 70%;
position: absolute;
top: 0;
padding-top: 30%;
left: 0;
padding-left: 7.5%;
padding-right: 7.5%;
text-align: center;
box-shadow: 0 0 0 4px $yellow inset;
border-radius: 50%;
z-index: 1;
span{
display: block;
&#artist{
font-weight: 700;
margin-bottom: 5px;
}
&#song{
font-size: 0.8em;
color: darken($tan, 55%);
text-transform: capitalize;
}
}
}
#pause{
width: 23px;
height: 25px;
position: absolute;
top: 65%;
left: 50%;
margin-left: -11.5px;
z-index:4;
display: none;
&:before{
content: ' ';
display: block;
height: 25px;
width: 6px;
background: $orange;
position: absolute;
top: 0;
left: 0;
}
&:after{
content: ' ';
display: block;
height: 25px;
width: 6px;
position: absolute;
top: 0;
right: 0;
background: $orange;
}
&:hover{
cursor: pointer;
&:before{
background: #DF7B46;
}
&:after{
background: #DF7B46;
}
}
}
#play{
width: 0px;
height: 0px;
z-index: 8;
position: absolute;
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
border-left: 20px solid $orange;
top: 65%;
left: 50%;
margin-left: -10px;
&:hover{
border-left: 20px solid #DF7B46;
cursor: pointer;
}
}
}
#playlist{
height: 180px;
width: 400px;
background: $tan;
box-shadow: 0 0 0 3px $orange inset, 0 0 0 7px $yellow inset;
top: 50%;
margin-top: -100px;
left: 150px;
padding: 10px 0;
position: absolute;
overflow: hidden;
border-top-right-radius: 20px;
border-bottom-right-radius: 20px;
&:before{
content: ' ';
display: block;
background-color: darken($tan, 5%);
mix-blend-mode: multiply;
width: 275px;
height: 275px;
border-radius: 50%;
position: absolute;
top: 50%;
margin-top: -137.5px;
left: -160px;
z-index:2;
}
ul{
overflow-y: auto;
overflow-x: hidden;
margin: 0;
padding:0;
height: 100%;
list-style-type: none;
&::-webkit-scrollbar {
display: none;
}
}
li{
a{
display: block;
width: 90%;
font-size: 0.8em;
padding: 0.4em 0 0.4em 125px;
border-bottom: 1px solid darken($tan, 10%);
box-sizing: border-box;
overflow: hidden;
white-space: nowrap;
color: darken($tan, 55%);
position: relative;
&:hover{
cursor: pointer;
border-bottom: 1px solid darken($tan, 20%);
color: #000;
}
&.active{
.waves{
content: '';
display: block;
position: absolute;
right: 3%;
top: auto;
bottom: 5px;
width: 3px;
height: 9px;
background: $orange;
animation: waves2 forwards 2s infinite;
&:before{
content: '';
display: block;
position: absolute;
left: -5px;
top: auto;
bottom: 0;
width: 3px;
height: 9px;
background: $orange;
animation: waves1 forwards 2s infinite;
}
&:after{
content: '';
display: block;
position: absolute;
left: auto;
top: auto;
bottom: 0;
right: -5px;
width: 3px;
height: 9px;
background: $orange;
animation: waves3 forwards 2s infinite;
}
}
}
}
&:last-child{
a{
border-bottom: 0;
}
}
}
}
#scrollbar{
height: 100%;
width: 40px;
right: 0;
position: absolute;
top: 0;
z-index: 8;
#bar{
border-radius: 4px;
height: 80%;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
position: absolute;
width: 5px;
background: darken($tan, 10%);
}
#marker{
position: absolute;
top: 10%;
left: 50%;
margin-left: -8px;
width: 12px;
height: 12px;
border-radius: 50%;
background: $ltorg;
border: 2px solid $orange;
box-shadow: 0 0 0 1px rgba($yellow, 0.5) inset, -1px 2px 0 0px rgba(darken($tan, 25%), 0.75);
&:after{
content: '';
display: block;
position: absolute;
height: 5px;
width: 5px;
border-radius: 50%;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
background: rgba($orange, 0.65);
}
}
}
#contact{
position: absolute;
bottom: 20px;
left: 20px;
p{
margin: 5px 0;
color: darken($tan, 55%);
font-size: 14px;
i{
color: $orange;
margin-right: 5px;
}
}
}
function getOffset(elapsedTime, fullTime, fullWidth){
return ((elapsedTime*fullWidth)/fullTime)
}
function drawArc (id, songTime){
var player = document.getElementById(id);
if(!player.paused){
var passedSecs = player.currentTime;
var duration = player.duration;
var passedTime = (passedSecs*100)/duration;
var path = document.getElementById(songTime);
var length = path.getTotalLength();
var offset = (passedTime*length)/100;
var dashOffset = length-offset;
document.getElementById(songTime).style.strokeDashoffset = -dashOffset;
}
}
var currDurr;
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://api.soundcloud.com/playlists/4350720?client_id=d7a1ecf371228b24c36e4c031255f0fa&enable_api=true');
xhr.send(null);
xhr.onreadystatechange = function () {
var DONE = 4; // readyState 4 means the request is done.
var OK = 200; // status 200 is a successful return.
if (xhr.readyState === DONE) {
if (xhr.status === OK){
SC.initialize({
client_id: 'd7a1ecf371228b24c36e4c031255f0fa'
});
var json = JSON.parse(xhr.responseText);
var tracks = json.tracks;
for(var i = 0; i<tracks.length; i++){
var playlist = document.querySelector('#playlist ul');
var songLi = document.createElement('li');
var song = document.createElement('a');
// var songSpan = document.createElement('span');
song.id = tracks[i].id;
song.dataset.trackId = tracks[i].id;
song.dataset.songLength = tracks[i].duration;
song.dataset.albumArt = tracks[i].artwork_url;
song.dataset.artist = tracks[i].user.username;
song.className = 'song';
song.innerHTML = tracks[i].title;
// song.appendChild(songSpan);
songLi.appendChild(song);
playlist.appendChild(songLi);
}
var songs = document.querySelectorAll('.song');
for(var i = 0; i<songs.length; i++){
songs[i].addEventListener('click', function(e){
var songLink, songStream;
currDurr = e.target.dataset.songLength;
SC.get('/tracks/'+e.target.id+'?enable_api=true').then(function(song){
if(document.getElementById('play')!==null){
document.getElementById('play').id = 'pause';
}
if(document.getElementById('pause')!==null){
document.getElementById('pause').style.display = 'block';
}
document.getElementById('artist').innerHTML = song.user.username;
document.getElementById('song').innerHTML = song.permalink;
songLink = song.stream_url;
var audio = document.getElementById('audio-player');
audio.src = songLink + '?client_id=d7a1ecf371228b24c36e4c031255f0fa';
audio.play();
drawArc('audio-player', 'song-time');
setInterval(function(){
return drawArc('audio-player', 'song-time');
}, 1000);
var allLinks = document.querySelectorAll('.song');
for(var j = 0; j<allLinks.length; j++){
if(allLinks[j].childNodes[1] !== undefined){
var childEl = allLinks[j].childNodes[1];
childEl.parentNode.removeChild(childEl);
}
allLinks[j].className = 'song';
}
e.target.className += ' active';
var activeSpan = document.createElement('span');
activeSpan.className = 'waves';
e.target.appendChild(activeSpan);
});
});
}
}
} else {
//Error Message Goes Here
}
}
window.onload = function(){
document.body.addEventListener('click', function(e){
if(e.target.id === 'pause'){
document.getElementById('audio-player').pause();
e.target.id = 'play';
} else if(e.target.id === 'play'){
document.getElementById('audio-player').play();
e.target.id = 'pause';
}
});
var mouseDown = false, markerdown = false;
var marker = document.getElementById('marker');
document.addEventListener('mousedown', function(e){
e.preventDefault();
mouseDown = true;
if(e.target.id === 'marker'){
markerdown = true;
}
});
document.addEventListener('mousemove', function(e){
if(mouseDown && !markerdown){ document.getElementById('player').style.top = (e.pageY) + 'px';
document.getElementById('player').style.left = e.pageX + 'px';
}
});
document.addEventListener('mouseup', function(e){
mouseDown = false;
markerdown = false;
});
document.getElementById('scrollbar').addEventListener('mousemove', function(e){
e.preventDefault();
if(markerdown){
var scrollBar = document.getElementById('bar');
var barStyles = getComputedStyle(scrollBar);
var markerStyles = getComputedStyle(marker);
var barHeight = Number(barStyles.height.replace('px',''));
var barTop = Number(barStyles.top.replace('px',''));
var barBottom = Number(barStyles.bottom.replace('px',''));
var scrollDiff = (e.pageY -document.getElementById('player').offsetTop + barTop)-16;
if(scrollDiff>0 && scrollDiff < (barHeight-8)){
var scrollPerc = (scrollDiff*100)/(barHeight-8);
var playList = document.getElementById('playlist').childNodes[3];
var getScrollTop = (Number(getComputedStyle(playList).height.replace('px',''))*scrollPerc)/100;
playList.scrollTop = getScrollTop/2;
marker.style.top = (scrollDiff + 16) + 'px';
}
}
});
}
document.querySelector('#playlist ul').addEventListener('scroll', function(e){
var list = e.target;
var maxScroll = list.scrollHeight - Number(getComputedStyle(list).height.replace('px',''));
var percentScrolled = ((list.scrollTop+8)*100)/maxScroll;
var barHeight = Number(getComputedStyle(document.getElementById('bar')).height.replace('px',''));
var fromBarTop = ((percentScrolled*(barHeight-12))/100);
var marker = document.getElementById('marker');
marker.style.top = fromBarTop + 'px';
});
Also see: Tab Triggers