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 class="container">
<!-- CAROUSEL -->
<div class="carousel">
<!-- SLIDES -->
<div class="slides">
<div class="items">
<div class="item"><div class="image" style="background-image:url(http://audeficheux.com/projects/carousel/src/medias/selah.png)"></div> <p class="artist">SELAH SUE</p><p class="track">Feel</p></div>
<div class="item"><div class="image" style="background-image:url(http://audeficheux.com/projects/carousel/src/medias/bruno.png)"></div> <p class="artist">BRUNO MARS</p><p class="track">Runaway Baby</p></div>
<div class="item"><div class="image" style="background-image:url(http://audeficheux.com/projects/carousel/src/medias/calvin.png)"></div> <p class="artist">CALVIN HARRIS</p><p class="track">Sweet Nothing</p></div>
<div class="item"><div class="image" style="background-image:url(http://audeficheux.com/projects/carousel/src/medias/onerep.png)"></div> <p class="artist">ONE REPUBLIC</p><p class="track">Preacher</p></div>
<div class="item"><div class="image" style="background-image:url(http://audeficheux.com/projects/carousel/src/medias/ellie.png)"></div> <p class="artist">ELLIE GOULDING</p><p class="track">Starry Eyed</p></div>
<div class="item"><div class="image" style="background-image:url(http://audeficheux.com/projects/carousel/src/medias/thomston.png)"></div> <p class="artist">THOMSTON</p><p class="track">Brain Dead</p></div>
<div class="item"><div class="image" style="background-image:url(http://audeficheux.com/projects/carousel/src/medias/halsey.png)"></div> <p class="artist">HALSEY</p><p class="track">New Americana</p></div>
<div class="item"><div class="image" style="background-image:url(http://audeficheux.com/projects/carousel/src/medias/frances.png)"></div> <p class="artist">FRANCES</p><p class="track">Grow</p></div>
</div>
</div>
<!-- SIBLINGS (PREVIOUS - NEXT) -->
<div class="siblings">
<a href="#" class="sibling prev"></a>
<a href="#" class="play"></a>
<a href="#" class="sibling next"></a>
</div>
<div class="seek-bar">
<div class="progress-bar"></div>
</div>
</div>
<div class="choice">
<div class="title">
<p>SONGS</p>
</div>
<div class="tracks">
<div class="track 1">
<div class="number">1</div>
<div class="name"><p>Selah Sue</p><p class="song">Feel</p></div>
<div class="speakers"></div>
</div>
<div class="track 2">
<div class="number">2</div>
<div class="name"><p>Bruno Mars</p><p class="song">Runaway Baby</p></div>
<div class="speakers invisible"></div>
</div>
<div class="track 3">
<div class="number">3</div>
<div class="name"><p>Calvin Harris</p><p class="song">Sweet Nothing</p></div>
<div class="speakers invisible"></div>
</div>
<div class="track 4">
<div class="number">4</div>
<div class="name"><p>One Republic</p><p class="song">Preacher</p></div>
<div class="speakers invisible"></div>
</div>
<div class="track 5">
<div class="number">5</div>
<div class="name"><p>Ellie Goulding</p><p class="song">Starry Eyed</p></div>
<div class="speakers invisible"></div>
</div>
<div class="track 6">
<div class="number">6</div>
<div class="name"><p>Thomston</p><p class="song">Brain Dead</p></div>
<div class="speakers invisible"></div>
</div>
<div class="track 7">
<div class="number">7</div>
<div class="name"><p>Halsey</p><p class="song">New Americana</p></div>
<div class="speakers invisible"></div>
</div>
<div class="track 8">
<div class="number">8</div>
<div class="name"><p>Frances</p><p class="song">Grow</p></div>
<div class="speakers invisible"></div>
</div>
</div>
</div>
<audio class="music"><source src="http://audeficheux.com/projects/carousel/src/medias/0.mp3" type="audio/mpeg"> Your browser doesn't support video API</audio>
</div>
<div class="credits"><a href="https://dribbble.com/shots/2166010-October-Select-Artist"> Design inspired by Regy Perlera </a></div>
/* SCROLL BAR */
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-track {
}
::-webkit-scrollbar-thumb {
-webkit-border-radius: 10px;
border-radius: 10px;
background: rgba(150,150,150,0.8);
}
body {
background:#eee;
font-family: Helvetica, sans-serif;
font-size: 14px;
}
.container {
margin: auto;
margin-top: 20px;
margin-bottom: 40px;
width: 300px;
-moz-box-shadow: 3px 3px 45px 10px #555;
-webkit-box-shadow: 3px 3px 45px 10px #555;
-o-box-shadow: 3px 3px 45px 10px #555;
box-shadow: 3px 3px 45px 10px #555;
}
.carousel {
width: 300px;
height: 325px;
position: relative;
background-image:url(http://audeficheux.com/projects/carousel/src/images/background0.png);
background-size: cover;
transition: background-image 0.5s ease;
}
/*Slides*/
.carousel .slides{
position: absolute;
top:0px;
right: 0px;
bottom:0;
left:0;
overflow: hidden;
}
.carousel .slides .items {
position: relative;
width: 10000px;
font-size:0;
padding-left: 37.5px;
transition: all ease-out 0.3s;
}
.carousel .slides .item {
margin: 25px 12.5px;
width: 200px;
height: 300px;
display: inline-block;
background-repeat: no-repeat;
}
.carousel .slides .item .image {
height: 200px;
width: 200px;
-moz-box-shadow: 6px 9px 20px #111;
-webkit-box-shadow: 6px 9px 20px #111;
-o-box-shadow: 6px 9px 20px #111;
box-shadow: 6px 9px 20px #111;
}
.carousel .slides .item p {
font-size: 12px;
color: white;
width: 200px;
position: absolute;
top: 250px;
text-align: center;
}
.carousel .slides .item .artist {
font-weight: 300;
font-size: 16px;
height: 25px;
}
.carousel .slides .item .track {
font-weight: 500;
font-size: 14px;
top : 275px;
}
/*Siblings*/
.carousel .siblings .sibling{
position: absolute;
width: 25px;
height: 200px;
top: 25px;
background: transparent;
text-align: center;
line-height:40px;
text-decoration: none;
}
.carousel .siblings .sibling.prev{
left:0px;
}
.carousel .siblings .sibling.next{
right:0px;
}
.carousel .siblings .play{
position: absolute;
width: 200px;
height: 200px;
top: 25px;
left: 50px;
background-image: url(http://audeficheux.com/projects/carousel/src/images/play.png);
background-repeat: no-repeat;
background-position: center;
text-align: center;
line-height:40px;
text-decoration: none;
transition: all 0.8s ease;
}
.carousel .siblings .play.invisible{
background-image: none;
transition: all 0.8s ease;
}
.carousel .siblings .play.invisible:hover{
background-image: url(http://audeficheux.com/projects/carousel/src/images/pause.png);;
}
/*Seek Bar */
.carousel .seek-bar {
position: absolute;
top: 315px;
width: 100%;
height: 10px;
background-color: rgba(0,0,0,0.2);
}
.carousel .seek-bar .progress-bar {
background-color: rgba(30,30,30,0.6);
width: 100%;
height: 100%;
-webkit-transform: scaleX(0);
-moz-transform: scaleX(0);
-ms-transform: scaleX(0);
-o-transform: scaleX(0);
transform: scaleX(0);
-webkit-transform-origin: 0;
-moz-transform-origin: 0;
-ms-transform-origin: 0;
-o-transform-origin: 0;
transform-origin: 0;
-webkit-transition: transform 0.2s;
-moz-transition: transform 0.2s;
-ms-transition: transform 0.2s;
-o-transition: transform 0.2s;
transition: transform 0.2s;
}
/* SONG LIST */
.container .choice {
width: 300px;
height: 200px;
background-color: white;
}
.container .choice .tracks {
height: 170px;
overflow: scroll;
}
.container .choice .title{
width: 290px;
height: 30px;
border-bottom: 1px solid #ccc;
padding-left: 10px;
}
.container .choice .title p{
height: 30px;
line-height: 30px;
vertical-align: middle;
color: #555;
font-size: 10px;
}
.container .choice .track{
width: 250px;
margin: auto;
height: 50px;
border-bottom: 1px solid #ccc;
padding-left: 10px;
font-weight: 300;
cursor: pointer;
}
.container .choice .track div{
display: inline-block;
}
.container .choice .track .number{
line-height: 50px;
}
.container .choice .track .name{
height: 30px;
vertical-align: middle;
padding-left: 25px;
}
.container .choice .track .name .song{
margin-top: 4px;
font-size: 12px;
}
.container .choice .track .speakers{
height: 20px;
width: 20px;
background-image: url(http://audeficheux.com/projects/carousel/src/images/speaker.png);
background-repeat: no-repeat;
vertical-align: middle;
float: right;
margin-top: 15px;
}
.container .choice .track .speakers.invisible{
display: none;
}
.credits {
width:250px;
text-align: center;
margin: auto;
margin-bottom: 10px;
font-size: 12px;
color: #555;
}
.credits a {
text-decoration: none;
color: black;
}
var Carousel = function ( $target )
{
this.$ = {};
this.$.container = $target;
this.$.carousel = this.$.container.find('.carousel');
this.$.prev = this.$.container.find('.prev');
this.$.next = this.$.container.find('.next');
this.$.play = this.$.container.find('.play');
this.$.slides_container = this.$.container.find('.slides .items');
this.$.slides = this.$.slides_container.find('.item');
this.$.seek_bar = this.$.container.find('.seek-bar');
this.$.progress_bar = this.$.container.find('.progress-bar');
this.$.choice = this.$.container.find('.choice');
this.$.tracks = this.$.choice.find('.tracks');
this.$.track = this.$.tracks.find('.track');
this.$.speakers = this.$.track.find('.speakers');
this.$.music = this.$.container.find('.music');
this.count = this.$.slides.length;
this.init_events();
};
Carousel.prototype.index = 0;
Carousel.prototype.count = 0;
Carousel.prototype.progress_ratio = 0;
Carousel.prototype.swipe = 0;
Carousel.prototype.init_events = function (){
var that = this;
/* On click on the next and prev button, swipe the carousel */
this.$.next.on('click', function(){
that.next();
return false;
});
this.$.prev.on('click', function(){
that.prev();
return false;
});
/* We click on one track name, change to that music and that image */
this.$.track.each(function (data) {
$(this).on('click', function (){
that.go_to( data, $carousel.index);
});
});
this.changeMusic();
/* CHECK WHEN WE CHANGE MUSIC ON KEYBOARD */
$(window).keydown(function(evt) {
if (evt.which == 39) {
that.next();
return false;
}
if (evt.which == 37) {
that.prev();
return false;
}
if (evt.which == 32) {
play = !play;
that.changeMusic();
return false;
}
});
/* CHECK WHEN WE PAUSE BY CLICKING ON THE IMAGE */
this.$.play.on('click', function(){
play = !play;
that.changeMusic();
return false;
});
this.$.speakers.on('click', function(){
if (that.$.music[0].volume == 1) {
that.$.music[0].volume = 0;
that.$.speakers.css({
"background-image": "url(http://audeficheux.com/projects/carousel/src/images/mute.png)"
});
}
else {
that.$.music[0].volume = 1;
that.$.speakers.css({
"background-image": "url(http://audeficheux.com/projects/carousel/src/images/speaker.png)"
});
}
});
/* CHECK WHEN THE MUSIC ENDS */
this.$.music.bind('ended', function(){
that.next();
});
/* FOR THE TOUCH CONTROL */
this.$.carousel.on('touchstart',function(e){
that.swipe = e.originalEvent.touches[0].clientX;
});
this.$.carousel.on('touchend',function(e){
if (e.originalEvent.changedTouches[0].clientX > that.swipe + 10)
that.prev();
else if (e.originalEvent.changedTouches[0].clientX < that.swipe - 10)
that.next();
/* The + / - 10 allows to not swipe when we touch the screen without purpose*/
});
/**** SEEK BAR ****/
window.setInterval(function () {
this.progress_ratio = that.$.music[0].currentTime / that.$.music[0].duration;
that.$.progress_bar.css({
transform: "scaleX(" + progress_ratio + ")"
});
}, 50);
/* Allows to change the current time of the song */
this.$.seek_bar.on('click', function (e) {
var x = e.clientX - that.$.seek_bar.offset().left,
ratio = x / that.$.seek_bar.width(),
time = ratio * that.$.music[0].duration;
that.$.music[0].currentTime = time;
});
};
Carousel.prototype.next = function()
{
this.go_to( this.index + 1, this.index);
};
Carousel.prototype.prev = function()
{
this.go_to( this.index - 1, this.index);
};
Carousel.prototype.go_to = function( index, currentIndex )
{
if (currentIndex != index) { //Avoid to start over the audio by clicking on the current music and mute the audio
index = index%this.count;
if (index < 0)
index = index + this.count;
this.$.carousel.css({
"background-image": "url(http://audeficheux.com/projects/carousel/src/images/background" + index + ".png)"
});
/* Make visible or invisible the speakers*/
this.$.speakers[currentIndex].classList.add('invisible');
this.$.speakers[index].classList.remove('invisible');
/* Change the source of the music */
this.$.music[0].setAttribute('src', 'http://audeficheux.com/projects/carousel/src/medias/' + index + '.mp3');
this.changeMusic();
/* Make the scroll follow the current music */
$carousel.$.tracks.animate({scrollTop:50*index - 50},300);
/* Animate the slider */
this.$.slides_container.css({
transform: "translateX(" + (-225)*index + "px)"
});
this.index = index;
}
};
Carousel.prototype.changeMusic = function()
{
/* Play or pause the music */
if (play == true) {
this.$.play[0].classList.add('invisible');
this.$.music[0].play();
}
else {
this.$.play[0].classList.remove('invisible');
this.$.music[0].pause();
}
};
var $carousel = new Carousel( $('.container ') );
var play = false
Also see: Tab Triggers