cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

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.

            
              <!--Pattern HTML-->
  <div id="pattern" class="pattern">
    <div class="c">
      <div class="c-list-container">
				<ul class="c-list">
					<li>
						<a href="#">
							<img src="http://bradfrost.github.com/this-is-responsive/patterns/images/fpo_landscape.png" alt="FPO Image" />
							<div class="summary">
								<h2>This is the first title</h2>
								<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eget lacus erat, sit amet tempor nibh. Aliquam erat volutpat. Nulla et. </p>
							</div>
						</a>
					</li>
					<li>
						<a href="#">
							<img src="http://bradfrost.github.com/this-is-responsive/patterns/images/fpo_landscape.png" alt="FPO Image" />
							<div class="summary">
								<h2>This is the second title</h2>
								<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eget lacus erat, sit amet tempor nibh. Aliquam erat volutpat. Nulla et. </p>
							</div>
						</a>
					</li>
					<li>
						<a href="#">
							<img src="http://bradfrost.github.com/this-is-responsive/patterns/images/fpo_landscape.png" alt="FPO Image" />
							<div class="summary">
								<h2>This is the third title</h2>
								<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eget lacus erat, sit amet tempor nibh. Aliquam erat volutpat. Nulla et. </p>
							</div>
						</a>
					</li>
					<li>
						<a href="#">
							<img src="http://bradfrost.github.com/this-is-responsive/patterns/images/fpo_landscape.png" alt="FPO Image" />
							<div class="summary">
								<h2>This is the fourth title</h2>
								<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eget lacus erat, sit amet tempor nibh. Aliquam erat volutpat. Nulla et. </p>
							</div>
						</a>
					</li>
					<li>
						<a href="#">
							<img src="http://bradfrost.github.com/this-is-responsive/patterns/images/fpo_landscape.png" alt="FPO Image" />
							<div class="summary">
								<h2>This is the fifth title</h2>
								<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eget lacus erat, sit amet tempor nibh. Aliquam erat volutpat. Nulla et. </p>
							</div>
						</a>
					</li>
					<li>
						<a href="#">
							<img src="http://bradfrost.github.com/this-is-responsive/patterns/images/fpo_landscape.png" alt="FPO Image" />
							<div class="summary">
								<h2>This is the sixth title</h2>
								<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eget lacus erat, sit amet tempor nibh. Aliquam erat volutpat. Nulla et. </p>
							</div>
						</a>
					</li>
					<li>
						<a href="#">
							<img src="http://bradfrost.github.com/this-is-responsive/patterns/images/fpo_landscape.png" alt="FPO Image" />
							<div class="summary">
								<h2>This is the seventh title</h2>
								<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eget lacus erat, sit amet tempor nibh. Aliquam erat volutpat. Nulla et. </p>
							</div>
						</a>
					</li>
					<li>
						<a href="#">
							<img src="http://bradfrost.github.com/this-is-responsive/patterns/images/fpo_landscape.png" alt="FPO Image" />
							<div class="summary">
								<h2>This is the eighth title</h2>
								<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eget lacus erat, sit amet tempor nibh. Aliquam erat volutpat. Nulla et. </p>
							</div>
						</a>
					</li>
					<li>
						<a href="#">
							<img src="http://bradfrost.github.com/this-is-responsive/patterns/images/fpo_landscape.png" alt="FPO Image" />
							<div class="summary">
								<h2>This is the ninth title</h2>
								<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eget lacus erat, sit amet tempor nibh. Aliquam erat volutpat. Nulla et. </p>
							</div>
						</a>
					</li>
				</ul>
			</div>
			<nav class="c-nav">
				<a href="#" class="prev">&larr; Prev</a>
				<a href="#" class="next">Next &rarr;</a>
			</nav>
		</div>
		
	</div>
	<!--End Pattern HTML-->
	
	<div class="container">	
		<section class="pattern-description">
			<h1>Fluid Carousel</h1>
			<p>A carousel whose panels expand to fit the screen width. When enough space becomes available, the carousel controls and titles overlay the carousel images, but small screens display the navigation and titles beneath the images. The user can click the previous and next buttons to advance, but touch-enabled users can also swipe through the carousel.</p>
		</section>
		<footer role="contentinfo">   
			<div>
				<nav id="menu">
					<a href="http://bradfrost.github.com/this-is-responsive/patterns.html">&larr;More Responsive Patterns</a>
				</nav>
			</div>
		</footer>
	</div>
            
          
!
            
              .c {
      position: relative;
  		margin: 0 auto;
		}
.c h2 {
   font-size: 1.6em; 
}
		.c-list-container {
			overflow: hidden;
			position: relative;
      z-index: 0;
		}
		.c-list {
			width: 99999em;
			position: relative;
			left: 0;
		}
    .c-list.animating {
      -webkit-transition: left 0.25s ease-out; 
     		-moz-transition: left 0.25s ease-out;  
       		-o-transition: left 0.25s ease-out; 
        	transition: left 0.25s ease-out;
    }
		
		.c li {
			float: left;
      position: relative;
		}
		.c li a {
			display: block;
		}
		.c img {
			display: block;
		}
		.c h2 {
			margin-top: 0;
		}
		.summary {
			padding: 1em;
		}
		.c-nav {
			clear: both;
			overflow: hidden;
			border-top: 1px solid #808080;
		}
		.c-nav a {
			float: left;
			width: 50%;
			padding: 1em;
			-webkit-transition: opacity 0.5s ease-out; 
     		-moz-transition: opacity 0.5s ease-out;  
       		-o-transition: opacity 0.5s ease-out; 
        	transition: opacity 0.5s ease-out;
		}
		.c-nav a.next {
			border-left: 1px solid #808080;
			text-align: right;
		}
		.c-nav a.inactive {
			opacity: 0.2;
			
		}
		
		/* Medium */
		@media screen and (min-width: 35em) {
			body:after { /* Conditional CSS http://adactio.com/journal/5429/ */
		        content: 'medium';
		        display: none;
	   		}
		}

		
		/* Large */
		@media screen and (min-width: 56.25em) {
			body:after { /* Conditional CSS http://adactio.com/journal/5429/ */
		        content: 'large';
		        display: none;
	   		}
		}
		
		/*Large with room to spare on either side */
		@media screen and (min-width: 56em) {
      .summary {
        position: absolute;
        bottom: 0;
        left: 0;
        z-index: 2;
        width: 100%;
        color: #fff;
        background: rgba(0,0,0,0.2);
      }
      .c h2 {
         font-size: 2.6em; 
      }
      .c-nav a {
				position: absolute;
				top: 40%;
				left: 1em;
				width: 4em;
				height: 2em;
				padding: 0;
				margin-top: -1em;
        color: #fff;
			}
			.c-nav a.next {
				left: auto;
				right: 1em;
				border: 0;
			}
		}

            
          
!
            
              (function(w){
  var sw = document.body.clientWidth,
    current = 0,
    breakpointSize = window.getComputedStyle(document.body,':after').getPropertyValue('content'),
		multiplier = 1, /*Determines the number of panels*/
		$carousel = $('.c'),
		$cList = $('.c-list'),
		$cContainer = $('.c-list-container'),
		$cWidth = $cContainer.outerWidth(),
    cLeft = $cList.css("left").replace("px",""),
		$li = $cList.find('li'),
		$liLength = $li.size(),
		numPages = $liLength/multiplier,
		$prev = $('.c-nav .prev'),
		$next = $('.c-nav .next');
	
	$(document).ready(function() {
		buildCarousel();
	});
	
	
	$(window).resize(function(){ //On Window Resize
		sw = document.body.clientWidth;
		$cWidth = $cContainer.width();
		breakpointSize = window.getComputedStyle(document.body,':after').getPropertyValue('content');  /* Conditional CSS http://adactio.com/journal/5429/ */
		sizeCarousel();
		posCarousel();
	});
	
	function sizeCarousel() { //Determine the size and number of panels to reveal
		current = 0;
		
		animLimit = $liLength/multiplier-1;
		
		$li.outerWidth($cWidth/multiplier); //Set panel widths
		
	}
	
	
	function buildCarousel() { //Build the Carousel
		sizeCarousel();

		if(Modernizr.touch) {
		   buildSwipe(); 
		}
	}
	
	function posCarousel() { //Animate Carousel. CSS transitions used for the actual animation.
		var pos = -current * $cWidth;
		$cList.addClass('animating').css("left",pos);
    
    setTimeout(function() {
      $cList.removeClass('animating');
      cLeft = $cList.css("left").replace("px","");
    }, 500);  // will work with every browser
	}
	
	$prev.click(function(e){ //Previous Button Click
		e.preventDefault();
		moveRight();
	});
  
	$next.click(function(e){ //Next Button Click
		e.preventDefault();
		moveLeft();
	});

  function moveRight() {
    if(current>0) {
			current--;
		}
		posCarousel();
  }
  
  function moveLeft() {
      if(current<animLimit) {
        current++;
      }
      posCarousel();
  }
  
	function buildSwipe() {
		var threshold = 80,
        origX = 0,
		    finalX = 0,
		    changeX = 0,
		    changeY = 0,
        curPos;
		    
		//Touch Start
		$cContainer.get(0).addEventListener("touchstart", function (event) {
		     origX = event.targetTouches[0].pageX;
        curPos = origX;
		});
		
		//Touch Move
		$cContainer.get(0).addEventListener("touchmove", function (event) {
		    finalX = event.touches[0].pageX,
        diffX = origX - finalX,
        leftPos = cLeft-diffX;
        
        event.preventDefault();
        $cList.css("left",leftPos);
		});
		
		//Touch Move
		$cContainer.get(0).addEventListener("touchend", function (event) {
      var diffX = origX - finalX,
          diffXAbs = Math.abs(diffX);
      
			if (diffX > 0 && diffXAbs > threshold) {
        moveLeft();
			} else if (diffX < 0 && diffXAbs > threshold) {
				moveRight();
      } else {
        posCarousel();
      }
			
      origX = finalX = diffX = 0;
		});
}
  
})(this);
            
          
!
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