Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

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.

+ add another resource

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <div id="main-stage">
        
		<div id="my-slider">
		    
		    <div class='slider-item' id="red-slide">
		    	<div class="slide-text">This is the first slide</div>
		    </div>
		    <div class='slider-item' id="green-slide">
		    	<div class="slide-text">This is the second slide <br/>with way more text</div>
		    </div>
		    <div class='slider-item' id="blue-slide">
		    	<div class="slide-text">Here is the third slide</div>
		    </div>
		    <div class='slider-item some-slide'>
		    	<div class="slide-text">Just some grey slide</div>
		    </div>
		    <div class='slider-item' id="image-slide">
		    	<div class="slide-text color-white">Hey there's an image here</div>
		    </div>
		    <div class='slider-item some-slide'>
		    	<div class="slide-text">Another grey slide</div>
		    </div>
		    
		    <div id="timeline-container">
		    	<div id="dots-container"></div>
		    </div>
		    
		    <div id="slider-button-prev" class="nav-button buttonMode"></div>
		    <div id="slider-button-next" class="nav-button buttonMode"></div>
		    
    </div>
        
</div>
              
            
!

CSS

              
                /* GENERAL STYLE */
@import url('https://fonts.googleapis.com/css?family=Open+Sans:300,400');

@media (max-width:500px) {
	.slide-text{
		font-size: 1.5em;
	}
	#slider-button-prev{
		left: 5px;
	}
	#slider-button-next{
		right: 5px;
	}
}
@media (min-width:501px) {
	.slide-text{
		font-size: 2em;
	}
	#slider-button-prev{
		left: 15px;
	}
	#slider-button-next{
		right: 15px;
	}
}

#main-stage{
	position: absolute;
	width: 100%;
	height: 100%;
	background-color: #fff;
}
.buttonMode { cursor: pointer; }

/* SLIDER */
#my-slider{
	position: absolute;
	width: 80%;
	height: 80%;
	min-width: 200px;
	min-height: 200px;
	max-height: 400px;
	left: 50%;
	top: 50%;
	-ms-transform: translate(-50%,-50%); /* IE 9 */
	-webkit-transform: translate(-50%,-50%); /* Safari */
	transform: translate(-50%,-50%);
}

.slider-item{
	position: absolute;
	width: 100%;
	height: 100%;
	text-align: center;
	opacity: 0;
	border-radius: 10px;
}

#red-slide{
	background-color: #f05b5b;
}
#green-slide{
	background-color: #77e78e;
}
#blue-slide{
	background-color: #6eccef;
}
#image-slide{
	background:url("http://pixel-salad.com/website/template7/img/background.jpg");
	background-size: cover;
	background-position: center center;
}
.some-slide{
	background-color: #ccc;
}

.slide-text{
	position: absolute;
	font-family: 'Open Sans', sans-serif;
	font-weight: 300;
	text-transform: uppercase;
	color: #272727;
	text-align: center;
	width: 60%;

	left: 50%;
	top: 50%;
	-ms-transform: translate(-50%,-50%); /* IE 9 */
	-webkit-transform: translate(-50%,-50%); /* Safari */
	transform: translate(-50%,-50%);
}
.color-white{
	color: white;
}

/* BUTTON NAVIGATION */
.nav-button{
	z-index: 1;
	opacity: 0;
	position:absolute;
	width: 28px;
	height: 100%;
	padding: 0 1%;
	background: url(http://pixel-salad.com/website/crossing-outdoor/wp-content/uploads/2018/my-files/button-previous.png);
	background-repeat: no-repeat;
	background-position: center center;
	transition: opacity .15s ease-in-out;
	-moz-transition: opacity .15s ease-in-out;
	-webkit-transition: opacity .15s ease-in-out
}
.nav-button:hover{
	opacity: 0.8!important;
	background-color: rgba(255, 255, 255, 0.5);
}
#slider-button-next{
	transform: rotate(180deg);
}
#my-slider:hover .nav-button{
	opacity: 0.5;
}

/* TIMELINE */
#timeline-container{
	position: absolute;
	left: 50%;
	-ms-transform: translateX(-50%); /* IE 9 */
	-webkit-transform: translateX(-50%); /* Safari */
	transform: translateX(-50%);
	width: 70%;
	white-space: nowrap;
	bottom: 15px;
}
#dots-container{
	position: relative;
	text-align: center;
}
.dot{
	position: relative;
	display: inline-block;
	height: 7px;
	width: 7px;
	border-radius: 7px;
	margin: 0 7px;
	background-color: #272727;
	overflow: hidden;
}
.dot-fill{
	position: relative;
	width: 0;
	height: 100%;
	background-color: white;
}
              
            
!

JS

              
                $(function(){
	
	var speedTransition = 500;
	var speedTimerSlider = 5000;
	
	var posSlide = 0;
	var nextPos = 0;
	var timerTimeline;
	var beginningSlide = true;
	var tabDots = [];
	var i = 0;

	//COUNT NUMBER OF SLIDES
	var totalNumSlide = $("#my-slider").find($(".slider-item")).length;

	function buildSlider(){
		//TARGET FIRST SLIDE AND MAKE IT APPEAR
		$(targetSlide(0)).css("opacity", 1);
		
		// HIDE SLIDES NON ACTIVE
		for( i=1 ; i< totalNumSlide ; i++){
			$(".slider-item").eq(i).css("display","none");
		}

		//ATTACH DOTS
		for( i=0 ; i<totalNumSlide ; i++){
			$("#dots-container").append("<div class='dot buttonMode'><div class='dot-fill'></div></div>");
			tabDots = document.getElementsByClassName("dot");
		}

		//START TIMER
		transformTimeLine();
	}

	function moveslider(Origin){
		//REMOVE CLICKS FROM THE DOTS DURING TRANSITION
		clickAllDots("remove");

		if($(this).hasClass("dot")){
			nextPos = $(this).index();
		}else{
			if((Origin == "timer") || (this.id=="slider-button-next")){
				//NEXT
				if(posSlide==totalNumSlide-1){
					nextPos = 0;
				}else{
					nextPos = posSlide+1;
				}
			}else{
				//PREV;
				if(posSlide==0){
					nextPos = totalNumSlide-1;
				}else{
					nextPos = Number(posSlide)-1;
				}
			}
		}

		//ALPHA TRANSITION
		var tempItemNow = targetSlide(posSlide);
		var tempNextItem = targetSlide(nextPos);
		tempItemNow.css("opacity",1);
		tempNextItem.css("opacity",0);
		tempNextItem.css("display","inline");

		tempNextItem.animate({ opacity: 1 },{ duration: speedTransition, easing: 'easeInOutQuint',});
		tempItemNow.animate({ opacity: 0 },{ duration: speedTransition, easing: 'easeInOutQuint',
			complete:function(){
				tempItemNow.css("display","none");
				posSlide = nextPos;
			}
		});
		//IF TRANSITION START FROM NAV BUTTON, RESET TIMELINE HERE
		if(Origin != "timer"){
			resetTimeline(false, $(".dot").eq(posSlide).find(".dot-fill"));
		} 
	}

	function transformTimeLine(){
		//TARGET THE DOT OF THE ACTUAL SLIDE AND STRETCH IT		
		var target = $(".dot").eq(nextPos);
		var targetFill = target.find(".dot-fill");
		target.removeClass("buttonMode");

		target.animate({ width: "20%" },{ duration: speedTransition, easing: 'easeInOutQuint', 
			complete:function(){
				//START TIMELINE
				moveTimeLine(targetFill);
				beginningSlide = false;
			}
		});
		//IF THE SLIDE DID NOT JUST BEGIN, DEFINE PREVIOUS SLIDE DOT TO RETRACT IT
		if(!beginningSlide){
			var previousTarget = $(".dot").eq(posSlide);
			previousTarget.animate({ width: "7px" },{ duration: speedTransition, easing: 'easeInOutQuint',});
			previousTarget.addClass("buttonMode");
		}
	}

  	function moveTimeLine(Target){
  		//REATTACH CLICKS TO THE DOTS AFTER TRANSITION
  		setTimeout( function(){
  			clickAllDots("add");
  		}, 200);
  		
  		//REMOVE CLICK EVENT ON THE STRETCHED DOT
		tabDots[nextPos].removeEventListener("click",moveslider);

  		//START TIMER
  		timerTimeline = setTimeout( function(){
  			resetTimeline(true, Target);
  		}, speedTimerSlider);
  		animationTimeline = Target.animate({ width: "100%" },{ duration: speedTimerSlider, easing: 'linear',});
  	}

  	function resetTimeline(Natural, Target){
  		//CLEAR TIMER AND STOP ANIMATION
  		clearTimeout(timerTimeline);
  		animationTimeline.stop();
		//TIMELINE DISAPPEARS
  		Target.animate({ opacity: 0 },{ duration: 200, easing: 'linear',
			complete:function(){
				//RESET PARAMS TIMELINE
				$(this).css({"width":0, "opacity":1});
  				// SWITCH SLIDE ONLY IF ORDERED BY THE TIMER
				if(Natural)moveslider("timer");
				//START TIMELINE AGAIN
				transformTimeLine();
			}
		});
  	}

  	function clickAllDots(State){
		if(State=="remove"){
			for( i=0 ; i<totalNumSlide ; i++) tabDots[i].removeEventListener("click",moveslider);
			document.getElementById("slider-button-prev").removeEventListener("click",moveslider);
			document.getElementById("slider-button-next").removeEventListener("click",moveslider);
		}else{
			for( i=0 ; i<totalNumSlide ; i++) tabDots[i].addEventListener("click",moveslider);
			document.getElementById("slider-button-prev").addEventListener("click",moveslider);
			document.getElementById("slider-button-next").addEventListener("click",moveslider);
		}
	}

  	function targetSlide(Index){
  		return $(".slider-item").eq(Index);
  	}

	buildSlider();

});
              
            
!
999px

Console