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.

            
              <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

            
          
!
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