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 URL's 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 it's URL and the proper URL extention.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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 class="wrapper">
<div class="player">
<div class="top">
<div id="yt-player" ref="yt-player"></div>
<div class="artist">
<div class="name">
{{artist}}
</div>
<div class="title">
{{title}}
</div>
</div>
<div class="time">
<div class="complete">{{showPlayTime}}</div>
<div class="current">{{showCurrentPlayTime}}</div>
</div>
<div class="record-wrapper">
<div class="record" :class="{spin: isPlaying}">
<div class="image" :style="{backgroundImage: `url(${recordImage})`}"></div>
</div>
</div>
</div>
<div class="controls">
<div class="grid">
<svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M1 5C1 2.79086 2.79086 1 5 1V1C7.20914 1 9 2.79086 9 5V5C9 7.20914 7.20914 9 5 9V9C2.79086 9 1 7.20914 1 5V5Z" stroke="#5D626C" stroke-width="2" stroke-linecap="square"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M13 1H21V9H13V1Z" stroke="#5D626C" stroke-width="2" stroke-linecap="square"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M1 13H9V21H1V13Z" stroke="#5D626C" stroke-width="2" stroke-linecap="square"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M13 13H21V21H13V13Z" stroke="#5D626C" stroke-width="2" stroke-linecap="square"/>
</svg>
</div>
<div class="repeat">
<svg width="18" height="20" viewBox="0 0 18 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M14 5H4V9H2V3H14V0L18 4L14 8V5ZM4 15H14V11H16V17H4V20L0 16L4 12V15Z" fill="#AFB5C0"/>
</svg>
</div>
<div class="prev" @click="prev">
<svg width="23" height="27" viewBox="0 0 23 27" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M17.8896 23.7417C19.6365 24.9935 22.0673 23.7449 22.0673 21.5958V5.40423C22.0673 3.25511 19.6365 2.0065 17.8896 3.25828L6.59146 11.3541C5.12173 12.4072 5.12173 14.5928 6.59147 15.6459L17.8896 23.7417Z" fill="#AFB5C0"/>
<rect y="4.26471" width="2" height="18" fill="#AFB5C0"/>
</svg>
</div>
<div class="play" @click="togglePlay">
<svg v-if="!isPlaying" width="42" height="51" viewBox="0 0 42 51" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M9.05427 42.3186C7.29861 43.4702 4.96631 42.2107 4.96631 40.1111V4.8889C4.96631 2.78927 7.29861 1.52983 9.05427 2.68141L35.9034 20.2925C37.4928 21.335 37.4928 23.665 35.9034 24.7075L9.05427 42.3186Z" fill="#383E47"/>
</svg>
<span v-else></span>
</div>
<div class="next" @click="next">
<svg width="23" height="27" viewBox="0 0 23 27" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M17.8896 23.7417C19.6365 24.9935 22.0673 23.7449 22.0673 21.5958V5.40423C22.0673 3.25511 19.6365 2.0065 17.8896 3.25828L6.59146 11.3541C5.12173 12.4072 5.12173 14.5928 6.59147 15.6459L17.8896 23.7417Z" fill="#AFB5C0"/>
<rect y="4.26471" width="2" height="18" fill="#AFB5C0"/>
</svg>
</div>
<div class="shuffle">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M6.59 5.17L1.41 0L0 1.41L5.17 6.58L6.59 5.17ZM10.5 0L12.54 2.04L0 14.59L1.41 16L13.96 3.46L16 5.5V0H10.5ZM9.42 10.82L10.83 9.41L13.96 12.54L16 10.5V16H10.5L12.55 13.95L9.42 10.82Z" fill="#AFB5C0"/>
</svg>
</div>
<div class="heart">
<a target="_blank" href="https://www.youtube.com/watch?v=8b-5N7B7qWI">
<svg width="24" height="21" viewBox="0 0 24 21" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M20.2501 11.3912L20.4728 11.1713C21.9577 9.70875 22.4703 7.53982 21.7944 5.57969C21.1185 3.61957 19.3717 2.20964 17.2912 1.94482C15.2106 1.68 13.1586 2.60641 12.001 4.33315C10.8433 2.60641 8.79134 1.68 6.71077 1.94482C4.63021 2.20964 2.88345 3.61957 2.20753 5.57969C1.53161 7.53982 2.04424 9.70875 3.52914 11.1713L12.0001 19.5341" stroke="#5D626C" stroke-width="2" stroke-linecap="square"/>
<rect width="2" height="8" transform="translate(12 22) rotate(90 8 0)" fill="#5D626C"/>
<rect width="2" height="8" transform="translate(15 11)" fill="#5D626C"/>
</svg></a>
</div>
</div>
<div class="timeline" @click="jumpTo" ref="timeline">
<div :style="{width: percentage + '%'}"></div>
</div>
</div>
<div class="cp">
<a target="_blank" href="https://www.instagram.com/p/BsYK3S9Bm32/">https://www.instagram.com/p/BsYK3S9Bm32/</a>
</div>
</div>
@import url('https://fonts.googleapis.com/css?family=Muli:400,700,900');
$offset: 70px;
$recordHeight: 495px;
$innerRecodHeight: 220px;
$backgroundColor: #A7C1DD;
$trackColor1: #4b75a0;
$trackColor2: darken($trackColor1, 10%);
#yt-player {
background-color: #000;
position: absolute;
opacity: 0;
}
@function record-rings($n) {
$value: '0 0 0 1px #111';
@for $i from 2 through $n {
@if $i % 5 == 0 {
$value: '#{$value}, 0px 0px 0px #{$i * 1}px #222';
} @else {
$value: '#{$value}, 0px 0px 0px #{$i * 1}px #111';
}
}
@return unquote($value);
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
body,
html {
background-color: $backgroundColor;
height: 100%;
position: relative;
z-index: -1;
}
.wrapper {
display: grid;
grid-template-rows: 1fr auto;
height: 100%;
margin: 0 auto;
position: relative;
width: 578px;
.cp {
text-align: center;
margin-bottom: 10px;
a {
color: darken($backgroundColor, 10%);
}
}
}
.player {
align-self: center;
background: linear-gradient(168.53deg, $trackColor1 -45.66%, $trackColor2 84.26%);
border-radius: 10px;
box-shadow: 0px 8px 4px rgba(0, 0, 0, 0.2);
display: grid;
grid-template-rows: (405px - 90px) 90px 7px;
height: 405px;
margin: 130px auto 0;
position: relative;
width: 578px;
&:before {
content: '';
background: darken($backgroundColor, 40%);
border-radius: 10px;
bottom: -30px;
filter: blur(90px);
height: 370px;
left: 20px;
position: absolute;
right: 20px;
z-index: -1;
}
.top {
position: relative;
.artist {
color: #fff;
font-family: Muli;
left: 0;
position: absolute;
text-transform: uppercase;
top: -100px;
z-index: 1;
.name {
color: rgba(255, 255, 255, 0.3);
font-size: 17px;
letter-spacing: 4px;
line-height: 20px;
position: relative;
&:after {
background: #fff;
content: '';
height: 2px;
left: -30px;
position: absolute;
top: 8px;
width: 20px;
}
}
.title {
font-size: 60px;
font-weight: 700;
line-height: 73px;
}
}
.time {
color: #fff;
font-family: Muli;
font-size: 90px;
position: absolute;
right: 0;
top: -148px;
.complete {
color: rgba(255, 255, 255, 0.3);
margin: 0 0 0 -40px;
}
.current {
font-weight: 700;
margin: -70px 0 0 0;
}
}
.record-wrapper {
height: $recordHeight - $offset;
overflow: hidden;
transform: translateY(-$offset);
.record {
background-image: linear-gradient(130deg, #070809 24%, #070809 35%, #676767 49%, #070809 64%, #070809 76%);
border: 7px solid #000;
border-radius: 100%;
box-sizing: border-box;
height: $recordHeight;
left: 50%;
margin-left: ((495px / 2) * -1);
position: absolute;
top: 0;
width: $recordHeight;
animation: spin 5s linear infinite;
animation-play-state: paused;
&.spin {
animation-play-state: running;
}
&:before {
background-color: #000;
border-radius: 100%;
content: '';
height: 10px;
left: 50%;
margin-left: -(10px/2);
margin-top: -(10px/2);
opacity: 1;
position: absolute;
top: 50%;
width: 10px;
z-index: 1;
}
&:after {
content: '';
border-radius: 100%;
box-shadow: record-rings(130);
height: $innerRecodHeight;
left: 50%;
margin-left: -($innerRecodHeight/2);
margin-top: -($innerRecodHeight/2);
opacity: 0.6;
position: absolute;
top: 50%;
width: $innerRecodHeight;
}
.image {
border: 41px solid #000;
box-sizing: border-box;
background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/279756/kl.png);
background-position: center;
transform: rotate(-45deg);
background-size: 180%;
border-radius: 100%;
content: '';
height: $innerRecodHeight;
left: 50%;
margin-left: -($innerRecodHeight/2);
margin-top: -($innerRecodHeight/2);
opacity: 1;
position: absolute;
top: 50%;
width: $innerRecodHeight;
opacity: 0.7;
}
}
}
}
.controls {
background-color: #fff;
position: relative;
display: flex;
justify-content: space-between;
align-items: center;
padding: 24px;
div {
cursor: pointer;
&.play {
margin-top: 0;
width: 41px;
height: 41px;
span {
position: relative;
top: 3px;
left: 5px;
&:after,
&:before {
content: '';
top: 0;
position: absolute;
background-color: rgb(56, 62, 71);
height: 40px;
width: 9px;
border-radius: 4px;
}
&:before {
left: 22px;
}
}
}
&.prev {
margin-top: 8px;
}
&.next {
transform: rotate(180deg);
margin-top: 0px;
}
&.repeat {
margin-top: 7px;
}
&.shuffle {
margin-top: 8px;
}
&.shuffle,
&.repeat,
&.next,
&.prev {
&:hover {
path {
fill: #383e47;
}
}
}
&.grid {
&:hover {
path {
stroke: $backgroundColor;
}
}
}
&.heart {
&:hover {
path {
stroke: #d25d5d;
}
rect {
fill: #d25d5d;
}
}
}
&:first-child,
&:last-child {
padding: 8px 8px 4px;
border-radius: 6px;
border: 1px solid #d8d8d8;
}
&:first-child {
margin-right: 80px;
}
&:last-child {
margin-left: 80px;
}
}
}
.timeline {
background-color: #c0c9d6;
border-radius: 0 0 10px 10px;
overflow: hidden;
position: relative;
width: 100%;
div {
transition: width 0.2s;
background-image: linear-gradient(90deg, $trackColor1 40%, $trackColor2 85%);
content: '';
height: 100%;
left: 0;
position: absolute;
}
}
}
let musicInterval = null;
let player;
const vm = new Vue({
data: {
videoId: 'bJl-avjRgzU',
artist: "Parcels",
title: "Lightenup",
duration: 178,
currentTime: 0,
isPlaying: false
},
computed: {
recordImage() {
return `https://img.youtube.com/vi/${this.videoId}/sddefault.jpg`;
},
percentage() {
return this.currentTime / this.duration * 100;
},
showPlayTime() {
const m = this.getMinutes(this.duration);
const s = this.getSeconds(this.duration);
return `${m}:${s}`;
},
showCurrentPlayTime() {
const m = this.getMinutes(this.currentTime);
const s = this.getSeconds(this.currentTime);
return `${m}:${s}`;
}
},
watch: {
currentTime(time) {
if (Math.round(time + 1) >= this.duration) {
this.togglePlay();
this.currentTime = 0;
player.stopVideo();
}
}
},
methods: {
prev() {
if(player) {
player.previousVideo();
}
},
next() {
if(player) {
console.log(player, player.getVideoUrl().split('?v=')[1])
player.nextVideo();
}
},
jumpTo(e) {
const trackPercentage = (e.layerX / this.$refs.timeline.offsetWidth) * 100;
this.playAt(this.duration / 100 * trackPercentage);
},
playAt(seconds) {
if(player) {
player.seekTo(seconds);
this.currentTime = seconds;
if(!this.isPlaying) {
this.togglePlay();
}
}
},
getMinutes(seconds) {
const m = Math.floor((seconds % 3600) / 60);
return m;
},
getSeconds(seconds) {
const s = Math.floor((seconds % 3600) % 60);
return (s <= 9 ? "0" : "") + s;
},
interval() {
this.currentTime = !player ? this.currentTime : Math.round(player.getCurrentTime());
},
togglePlay() {
if (!this.isPlaying) {
musicInterval = setInterval(this.interval, 1000);
player.playVideo();
player.unMute();
} else {
clearInterval(musicInterval);
player.pauseVideo();
}
this.isPlaying = !this.isPlaying;
}
}
});
vm.$mount(".wrapper");
function onYouTubeIframeAPIReady() {
player = new YT.Player('yt-player', {
videoId: vm.$data.videoId,
events: {
onReady() {
if(player) {
const [artist, title] = player.getVideoData().title.split(' - ');
const videoId = player.getVideoUrl().split('?v=')[1];
vm.$data.duration = Math.floor(player.getDuration());
vm.$data.title = title.split('|')[0];
vm.$data.artist = artist;
vm.$data.videoId = videoId;
}
}
}
});
}
Also see: Tab Triggers