Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

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.

Behavior

Auto Save

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

              
                <h1>Parallax Slider with TimelineMax (transitions not so smooth yet)</h1>
<!--//
/*
GSAP Parallax Slider with TimelineMax
*/
//-->
	<div id='slider'>
		<div id='strip'>
			<div class='slide'>
				<div  class='slideBkg'>
					<img class='slideBkgImg' src='http://lorempixel.com/1920/1080/food/?rnd=qaz'/></div>
				<div class='titleBox'>
					<h1>SLIDE <span> 1</span></h1>
					<description><p>The internet was missing the ability to provide custom-sized placeholder images of Bill Murray. Now it can.</p></description>
					<xButton></xButton>
				</div>
				<div class='map'>
					<img class='map' src='http://lorempixel.com/200/300/food/?rnd=wsx'/>
					<p class='mapText'>All Regions</p>     
				</div>
			</div>

	        <div class='slide'>
				<div  class='slideBkg'>
					<img class='slideBkgImg' src='http://lorempixel.com/1920/1080/food/?rnd=edc'/></div>
				<div class='titleBox'>
					<h1>SLIDE <span> 2</span></h1>
					<description><p>The internet was missing the ability to provide custom-sized placeholder images of Bill Murray. Now it can.</p></description>
					<xButton></xButton>
				</div>
				<div class='map'>
					<img class='map' src='http://lorempixel.com/200/300/food/?rnd=rfv'/>
					<p class='mapText'>All Regions</p>     
				</div>
			</div>

			<div class='slide'>
				<div  class='slideBkg'>
					<img class='slideBkgImg' src='http://lorempixel.com/1920/1080/food/?rnd=tgb'/></div>
				<div class='titleBox'>
					<h1>SLIDE <span> 3</span></h1>
					<description><p>The internet was missing the ability to provide custom-sized placeholder images of Bill Murray. Now it can.</p></description>
					<xButton></xButton>
				</div>
				<div class='map'>
					<img class='map' src='http://lorempixel.com/200/300/food/?rnd=asd'/>
					<p class='mapText'>All Regions</p>     
				</div>
			</div>

			<div class='slide'>
				<div  class='slideBkg'>
					<img class='slideBkgImg' src='http://lorempixel.com/1920/1080/food/?rnd=zxc'/></div>
				<div class='titleBox'>
					<h1>SLIDE <span> 4</span></h1>
					<description><p>The internet was missing the ability to provide custom-sized placeholder images of Bill Murray. Now it can.</p></description>
					<xButton></xButton>
				</div>
				<div class='map'>
					<img class='map' src='http://lorempixel.com/200/300/food/?rnd=qwe'/>
					<p class='mapText'>All Regions</p>     
				</div>
			</div>	
			
			<div class='slide'>
				<div  class='slideBkg'>
					<img class='slideBkgImg' src='http://lorempixel.com/1920/1080/food/?rnd=ewq'/></div>
				<div class='titleBox'>
					<h1>SLIDE <span> 5</span></h1>
					<description><p>The internet was missing the ability to provide custom-sized placeholder images of Bill Murray. Now it can.</p></description>
					<xButton></xButton>
				</div>
				<div class='map'>
					<img class='map' src='http://lorempixel.com/200/300/food/?rnd=dsa'/>
					<p class='mapText'>All Regions</p>     
				</div>
			</div>

			<div class='slide'>
				<div  class='slideBkg'>
					<img class='slideBkgImg' src='http://lorempixel.com/1920/1080/food/?rnd=cxzd'/></div>
				<div class='titleBox'>
					<h1>SLIDE <span> 6</span></h1>
					<description><p>The internet was missing the ability to provide custom-sized placeholder images of Bill Murray. Now it can.</p></description>
					<xButton></xButton>
				</div>
				<div class='map'>
					<img class='map' src='http://lorempixel.com/200/300/food/?rnd=eb'/>
					<p class='mapText'>All Regions</p>     
				</div>
			</div>

			<div class='slide'>
				<div  class='slideBkg'>
					<img class='slideBkgImg' src='http://lorempixel.com/1920/1080/food/?rnd=uik'/></div>
				<div class='titleBox'>
					<h1>SLIDE <span> 7</span></h1>
					<description><p>The internet was missing the ability to provide custom-sized placeholder images of Bill Murray. Now it can.</p></description>
					<xButton></xButton>
				</div>
				<div class='map'>
					<img class='map' src='http://lorempixel.com/200/300/food/?rnd=poi'/>
					<p class='mapText'>All Regions</p>     
				</div>
			</div>

			<div class='slide'>
				<div  class='slideBkg'>
					<img class='slideBkgImg' src='http://lorempixel.com/1920/1080/food/?rnd=iop'/></div>
				<div class='titleBox'>
					<h1>SLIDE <span> 8</span></h1>
					<description><p>The internet was missing the ability to provide custom-sized placeholder images of Bill Murray. Now it can.</p></description>
					<xButton></xButton>
				</div>
				<div class='map'>
					<img class='map' src='http://lorempixel.com/200/300/food/?rnd=pkm'/>
					<p class='mapText'>All Regions</p>     
				</div>
			</div>

			<div class='slide'>
				<div  class='slideBkg'>
					<img class='slideBkgImg' src='http://lorempixel.com/1920/1080/food/?rnd=mju34'/></div>
				<div class='titleBox'>
					<h1>SLIDE <span> 9</span></h1>
					<description><p>The internet was missing the ability to provide custom-sized placeholder images of Bill Murray. Now it can.</p></description>
					<xButton></xButton>
				</div>
				<div class='map'>
					<img class='map' src='http://lorempixel.com/200/300/food/?rnd=odfim'/>
					<p class='mapText'>All Regions</p>     
				</div>
			</div>
			
			<div class='slide'>
				<div  class='slideBkg'>
					<img class='slideBkgImg' src='http://lorempixel.com/1920/1080/food/?rnd=szxok'/></div>
				<div class='titleBox'>
					<h1>SLIDE <span> 10</span></h1>
					<description><p>The internet was missing the ability to provide custom-sized placeholder images of Bill Murray. Now it can.</p></description>
					<xButton></xButton>
				</div>
				<div class='map'>
					<img class='map' src='http://lorempixel.com/200/300/food/?rnd=98jdvf'/>
					<p class='mapText'>All Regions</p>     
				</div>
			</div>

			<div class='slide'>
				<div  class='slideBkg'>
					<img class='slideBkgImg' src='http://lorempixel.com/1920/1080/food/?rnd=okjismndfv0'/></div>
				<div class='titleBox'>
					<h1>SLIDE <span> 11</span></h1>
					<description><p>The internet was missing the ability to provide custom-sized placeholder images of Bill Murray. Now it can.</p></description>
					<xButton></xButton>
				</div>
				<div class='map'>
					<img class='map' src='http://lorempixel.com/200/300/food/?rnd=isdknj'/>
					<p class='mapText'>All Regions</p>     
				</div>
			</div>

			<div class='slide'>
				<div  class='slideBkg'>
					<img class='slideBkgImg' src='http://lorempixel.com/1920/1080/food/?rnd=sd9un4'/></div>
				<div class='titleBox'>
					<h1>SLIDE <span> 12</span></h1>
					<description><p>The internet was missing the ability to provide custom-sized placeholder images of Bill Murray. Now it can.</p></description>
					<xButton></xButton>
				</div>
				<div class='map'>
					<img class='map' src='http://lorempixel.com/200/300/food/?rnd=sdcvy7'/>
					<p class='mapText'>All Regions</p>     
				</div>
			</div>
            
            <div class='slide'>
				<div  class='slideBkg'>
					<img class='slideBkgImg' src='http://lorempixel.com/1920/1080/food/?rnd=husdb4'/></div>
				<div class='titleBox'>
					<h1>SLIDE <span> 13</span></h1>
					<description><p>The internet was missing the ability to provide custom-sized placeholder images of Bill Murray. Now it can.</p></description>
					<xButton></xButton>
				</div>
				<div class='map'>
					<img class='map' src='http://lorempixel.com/200/300/food/?rnd=y8bnec'/>
					<p class='mapText'>All Regions</p>     
				</div>
			</div>
            
            <div class='slide'>
				<div  class='slideBkg'>
					<img class='slideBkgImg' src='http://lorempixel.com/1920/1080/food/?rnd=sidjhnv34'/></div>
				<div class='titleBox'>
					<h1>SLIDE <span> 14</span></h1>
					<description><p>The internet was missing the ability to provide custom-sized placeholder images of Bill Murray. Now it can.</p></description>
					<xButton></xButton>
				</div>
				<div class='map'>
					<img class='map' src='http://lorempixel.com/200/300/food/?rnd=ksjdcvn91'/>
					<p class='mapText'>All Regions</p>     
				</div>
			</div>
            
            <div class='slide'>
				<div  class='slideBkg'>
					<img class='slideBkgImg' src='http://lorempixel.com/1920/1080/food/?rnd=12ghdb'/></div>
				<div class='titleBox'>
					<h1>SLIDE <span> 15</span></h1>
					<description><p>The internet was missing the ability to provide custom-sized placeholder images of Bill Murray. Now it can.</p></description>
					<xButton></xButton>
				</div>
				<div class='map'>
					<img class='map' src='http://lorempixel.com/200/300/food/?rnd=67sdcg'/>
					<p class='mapText'>All Regions</p>     
				</div>
			</div>
            
            <div class='slide'>
				<div  class='slideBkg'>
					<img class='slideBkgImg' src='http://lorempixel.com/1920/1080/food/?rnd=sdc3'/></div>
				<div class='titleBox'>
					<h1>SLIDE <span> 16</span></h1>
					<description><p>The internet was missing the ability to provide custom-sized placeholder images of Bill Murray. Now it can.</p></description>
					<xButton></xButton>
				</div>
				<div class='map'>
					<img class='map' src='http://lorempixel.com/200/300/food/?rnd=sdc78'/>
					<p class='mapText'>All Regions</p>     
				</div>
			</div>
            
            <div class='slide'>
				<div  class='slideBkg'>
					<img class='slideBkgImg' src='http://lorempixel.com/1920/1080/food/?rnd=84cb'/></div>
				<div class='titleBox'>
					<h1>SLIDE <span> 17</span></h1>
					<description><p>The internet was missing the ability to provide custom-sized placeholder images of Bill Murray. Now it can.</p></description>
					<xButton></xButton>
				</div>
				<div class='map'>
					<img class='map' src='http://lorempixel.com/200/300/food/?rnd=wdeef4'/>
					<p class='mapText'>All Regions</p>     
				</div>
			</div>
            
		</div>


    </div>
  
	<div id="buttons">
		<div id="next"></div>
		<div id="prev"></div>
	</div>   
</body>
</html>

              
            
!

CSS

              
                html {
    font-size:16px;
    font-family: sans-serif;
    color:rgba(255,255,255,1);overflow:hidden;
}
*,html{
    -moz-user-select: none; 
    -webkit-user-select: none;
    -ms-user-select: none;
    user-select: none; 
    -webkit-user-drag: none;
    user-drag: none;   
}
p {
    line-height: 20px;font-size: 1em; margin:2px;
}
body {
    overflow-x: none;
    -webkit-overflow-scrolling: touch;margin:0;
    /*width:1080; height:1920;transform: rotate(90deg);*/
    width:1920; height:1080;
}

.slide{
	position:absolute;top:0;display:block;width:1544px;height:1080px;border-left:3px white;border-right:3px white;overflow:hidden;
}

.slideBkg{
    z-index:-10000;position:absolute;top:0px;left:0px;
}
#next,#prev{
	position:fixed; top:508px;margin:0;width:64px;height:64px;
}
#next{
	background-image:url('http://fakeimg.pl/64x64/000000/?text=>&font=museo&font_size=64');
	right:100px;
}
#prev{
	background-image:url('http://fakeimg.pl/64x64/000000/?text=<&font=museo&font_size=64');
	left:100px;
}
.titleBox {
    display:block;top:60px;left:760px;width:694px;height:124px;max-width:694px;opacity:0;
}

description {
    padding: 6px 8px;
    color:rgba(255,255,255,.9);
    display:block;width:554px;height:72px;position:absolute;top:42px;left:0px;background:rgba(0,0,0,1);
}

.title {
    font-size: 26px;
    padding: 6px 8px;line-height: 26px;
    display:block;width:554px;height:30px;position:absolute;top:0;left:0;background:rgba(0,0,0,.6);
}

xButton{
    display:block;width:124px;height:124px;border:1px solid rgba(0,0,0,.6);border-left: none;position:absolute;top:0;left:570px;
}

.xButton-x{
   transform: rotate(45deg);/*width:124;height: 100%;*/position:absolute;top:28px;left:28px;
}

.map{
    position:absolute;right:64px;top:64px;width:auto;height: auto;
}

.titleBox>h1{
    margin:0;display:block;
    font-size: 24px;font-weight: 500;
    padding: 6px 8px;line-height: 26px;
    display:block;width:554px;height:30px;position:absolute;top:0;left:0;background:rgba(0,0,0,.6);  
}


#slider,#strip,.slide,.slideBkg,.titleBox,.map{
	position:absolute;
}

/* Utils
--------------------------------------------------*/
.alignRight{
 text-align:right;   
}
.blackshadow{
    text-shadow: 1px 1px 1px rgba(0,0,0,.5);
}

              
            
!

JS

              
                var appRunning = false;
var _stage_width = 1920;
var _stage_height = 1080;
var _slideContentWidth = 1544;
var _slide_height = 1080;
var _slide_margin = 185;
var _slide_borderWidth = 3;
var _slide_width = _slideContentWidth + _slide_borderWidth*2;
var totalSlides = 17;
var _carousel_width = _slide_width * totalSlides;
var _strip_width = _slide_width * (totalSlides +2);

var timeline;
var timelineStep = 2; // 1 second

var timelineProgress = 0;
var former_TLProgress = 0;
$( document ).ready(function( $ ) {
    init();
});
var sw = _strip_width;
var sx = 0;
var tl;
var strip = $('#strip');
//var timeLineWidth = ((totalSlides+1)*_slide_width) + _slide_margin;
var timeLineWidth = ((totalSlides+2)*_slide_width);

var defaultEasing = Linear.easeNone;
//var defaultEasing = Quart.easeInOut;

var timeline_TimeScale = 1.4;

function arrivedToLabel(){
	console.log(tl.currentLabel());
	//tl.pause();
	//turn buttons ON
	$('#buttons').css('display', 'block');
}

function slider_Next(){
	sortSlidesDepths('up');
	tl.tweenTo(tl.getLabelAfter(),{onComplete:arrivedToLabel, ease:Strong.easeOut});
}

function slider_Prev(){
	sortSlidesDepths('down');
	tl.tweenTo(tl.getLabelBefore(),{onComplete:arrivedToLabel, ease:Strong.easeOut});
}

function init(){
	
	TweenLite.ticker.addEventListener("tick", appTick);
	
	//Clone first and last slides, place first clone last and last clone first
    var firstclone=$('#strip>.slide:first').clone();
    $('#strip>.slide:last').clone().prependTo($('#strip'));
    firstclone.appendTo($('#strip'));
	
	//make slide strip by stitching them on a row
	$('#slider>#strip>.slide').each(function(n,el){
		var p = $(el).css('position');
		//console.log( "p : " + p );
		$(el).css('left',_slide_width*n+'px');
		$(el).css('top','0px');
	});
	
	//Buttons
	$('#next').click(function(){
		//tween timeline to next timeline
		
		if(tl.isActive() || tl.progress==1) {
			return;
		}
		//hide buttons
		$('#buttons').css('display', 'none');
		//move on
		slider_Next();
		//console.log('arrivedToLabel: '+arrivedToLabel + ' LabelAfter: ' +tl.getLabelAfter());
		//tl.tweenTo(tl.getLabelAfter(),{onComplete:arrivedToLabel, ease:Strong.easeOut});
		
		//TweenMax.to(tl,2,{time:tl.getLabelAfter()});
	});
	
	$('#prev').click(function(){
		//tween timeline to next timeline
		if(tl.isActive()) {
			return;
		}
		//hide buttons
		$('#buttons').css('display', 'none');
		//move on
		slider_Prev();
		//tl.tweenTo(tl.getLabelBefore(),{onComplete:arrivedToLabel, ease:Strong.easeOut});
	});
	//Place slider and strip on place:
	$('#slider').css('left',_slide_margin+'px');
	//$('#strip').css('left','-'+_slide_width+'px');
	$('#strip').css('left','0px');
	
	//Place slide backgrounds on place
	/*$('.slide>.slideBkg').each(function(n,el){
		$(el).css('left','-'+_slide_margin+'px');
	}*/
	//sx = $('#strip').offset().left;
	
	//Calculate boundaries for draggable ? Maybe don't
	//$('sliderWrapper').css('left','-'+((gridWidth*(totalSlides+1))-(_slide_margin*2))+'px').css('height',_slide_height-2+'px');
    //$('sliderWrapper').css('width',((gridWidth*(totalSlides+1))-(_slide_margin*2))+'px');
	
	//Make strip draggable
	/*Draggable.create("#strip", {
		type:"x",
		edgeResistance:1,
		//bounds:{top:00, left:0, width:-_strip_width, height:0},
		bounds:{minX:-(timeLineWidth), maxX:_slide_width, minY:0, maxY:0},
		throwProps:true,
		snap: {
			x: function(endValue) {
				return Math.round(endValue / _slide_width) * _slide_width;
			}
		}
	});*/
	
	
	//Create greensock timeline
	tl = new TimelineMax();
	tl.pause();
	//tl.timeScale( timeline_TimeScale ) 
	//Calculate things
	//var BegginingTimeOffset = (timelineStep*(sw-_slide_margin))/sw;
	//add labels and tweens
	//var startTime = 1-BegginingTimeOffset;
	var startTime = 0;
	//var endTime = (totalSlides+1)-BegginingTimeOffset;
	var endTime = (totalSlides+3);
	tl.add('beginning', startTime).add('ending', endTime);
	var slide_i,label,s_time;
	var td = timelineStep;
	//slide_titleBox = $('.slide>.titleBox').eq(0);
	//tl.to(slide_titleBox,td,{x:60, alpha:1},s_time-td);
	//slide_titleBox.css('opacity',1).css('left','60px');
	//tl.to(slide_titleBox,td,{x:760, alpha:0},0);
	$('#strip').css('left',_slide_width+'px');
	//tl.to($('#strip'),totalSlides+3,{x:-timeLineWidth},0);
	//tl.play();
	//tl.progress(0);
	for (var i = 0; i <= totalSlides+2; i++) {
		var ni = (i + 1);
		label = 'slide_' + ni;
		s_time = i * timelineStep;
		console.log(i + ' ' + label +  ' ---> time: ' + s_time);
		tl.add(label, s_time);
		
		//tl.to(slider, slider_Step, { x:'+=' +  }, 'slide_' + (i + 1));
		slide_titleBox = $('.slide>.titleBox').eq(i);
		slide_map = $('.slide>.map').eq(i);
		slide_bkg = $('.slide>.slideBkg').eq(i);
		tl.to($('#strip'),td,{x:'-='+_slide_width},s_time-td);
		tl.to(slide_titleBox,td,{x:-700, alpha:1},s_time-td);
		tl.to(slide_bkg,td,{x:-185},s_time-td);
		//tl.to(slide_titleBox,td,{x:760, alpha:0},(s_time));
		/*tl.to(slide_titleBox,td,{x:1000, alpha:1},s_time);
		tl.from(slide_map,td,{x:100, alpha:1},s_time-td);
		tl.to(slide_map,td,{x:100, alpha:1},s_time);
		tl.from(slide_bkg,timelineStep,{x:-(_slide_margin*2)},(s_time-td));
		tl.to(slide_bkg,timelineStep,{x:0},s_time);*/
	}
	slide_titleBox = $('.slide>.titleBox:last');
	
	/**/
	//green light
	//console.log( "timeLineWidth : " + timeLineWidth );
	
	appRunning = true;
}

var mouse_x = 0;
var mouse_x_speed = 0;
var mouse_is_down = false;
var dragging = false;

function sortSlidesDepths(i_dir){
	if(i_dir=='up'){
		$('.slide').each(function(index){
			$( this ).css('z-index',index);
		});			
	} else {
		$('.slide').each(function(index){
			$( this ).css('z-index',-index);
		});			
	}
}




$( document ).mousemove(function( event ) {
  mouse_x_speed = event.pageX - mouse_x;
  mouse_x = event.pageX;
});

$( document ).mouseup(function( event ) {
    mouse_is_down = false;
	dragging = false;
	if(mouse_x_speed>0){
		//slider_Prev();
		return;
	}
	if(mouse_x_speed<0){
		//slider_Next();
		return;
	}
  })
  .mousedown(function( event ) {
	mouse_is_down = true;
	dragging = true;
    //mouse_x = event.pageX;
  });

function appTick()
{
    if(!appRunning) return;
	//var pos = $('#strip').position();//.left;
	
		//do dragging
	if(dragging){
		//tl.progress(tl.progress()+mouse_x_speed);
	}
		//translate strip position to timeline progress
	var ofs = $('#strip').offset();//.left;
	sx = Math.round(ofs.left);
	//sx = $('#strip').offset();
	//timelineProgress = sx / -timeLineWidth;
	if(former_TLProgress != timelineProgress){
		//console.log( "timelineProgress : " + sx + ' --->  ' + timelineProgress );
		//tl.progress(timelineProgress);
		//console.log(tl.progress());
	}
	former_TLProgress = timelineProgress;
}




              
            
!
999px

Console