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

              
                <head>
		<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
		<title>Sliding Carousel Demonstration Test</title>
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script type="text/javascript">
$(document).ready(function() {
			var carousel = $("#carousel").slidingCarousel({
				squeeze: 100
			});
});
</script>

	</head>
	<body>


<div id="carousel">

<div class="slide">
<p><img class="carousel-image" alt="Image Caption" src="https://unsplash.it/300/200?image=432">
<span> Curabitur nec dapibus neque. Aenean orci enim, rutrum ac lacinia in, dapibus sit amet lorem.	</span></p>
</div>

<div class="slide">
<p><a href="#"><img class="carousel-image" alt="Image Caption" src="https://unsplash.it/300/200?image=232"></a>
<span> Curabitur nec dapibus neque. Aenean orci enim, rutrum ac lacinia in, dapibus sit amet lorem.	</span></p>
</div>
  
<div class="slide">
<p><a href="#"><img class="carousel-image" alt="Image Caption" src="https://unsplash.it/300/200?image=200"></a>
<span> Curabitur nec dapibus neque. Aenean orci enim, rutrum ac lacinia in, dapibus sit amet lorem.	</span></p>
</div>

<div class="slide">
<p><a href="#"><img class="carousel-image" alt="Image Caption" src="https://unsplash.it/300/200?image=350"></a>
<span> Curabitur nec dapibus neque. Aenean orci enim, rutrum ac lacinia in, dapibus sit amet lorem.	</span></p>
</div>

<div class="slide">
<p><a href="#"><img class="carousel-image" alt="Image Caption" src="https://unsplash.it/300/200?image=400"></a>
<span> Curabitur nec dapibus neque. Aenean orci enim, rutrum ac lacinia in, dapibus sit amet lorem.	</span></p>
</div>

<div class="slide">
<p><a href="#"><img class="carousel-image" alt="Image Caption" src="https://unsplash.it/300/200?image=450"></a>
<span> Curabitur nec dapibus neque. Aenean orci enim, rutrum ac lacinia in, dapibus sit amet lorem.	</span></p>
</div>

<div class="slide">
<p><a href="#"><img class="carousel-image" alt="Image Caption" src="https://unsplash.it/300/200?image=500"></a>
<span> Curabitur nec dapibus neque. Aenean orci enim, rutrum ac lacinia in, dapibus sit amet lorem.	</span></p>
</div>

<div class="slide">
<p><a href="#"><img class="carousel-image" alt="Image Caption" src="https://unsplash.it/300/200?image=550"></a>
<span> Curabitur nec dapibus neque. Aenean orci enim, rutrum ac lacinia in, dapibus sit amet lorem.	</span></p>
</div>

<div class="slide">
<p><a href="#"><img class="carousel-image" alt="Image Caption" src="https://unsplash.it/300/200?image=600"></a>
<span> Curabitur nec dapibus neque. Aenean orci enim, rutrum ac lacinia in, dapibus sit amet lorem.	</span></p>
</div>

<div class="slide">
<p><a href="#"><img class="carousel-image" alt="Image Caption" src="https://unsplash.it/300/200?image=630"></a>
<span> Curabitur nec dapibus neque. Aenean orci enim, rutrum ac lacinia in, dapibus sit amet lorem.	</span></p>
</div>

<div class="navigate-left"><img src="https://images.vexels.com/media/users/3/128922/isolated/preview/1cec3d0747fc796080b17ca07e14d187--cone-redondo-da-seta-do-aeroporto-de-viagem-by-vexels.png" width="35px"></div>
<div class="navigate-right"><img src="https://images.vexels.com/media/users/3/128927/isolated/preview/25652eb37d257753ffab9b4ac8edfa28--cone-de-rodada-do-aeroporto-de-viagem-seta-by-vexels.png" width="35px"></div>
  
</div>
              
            
!

CSS

              
                #carousel {
  height: 280px;
  width: 960px;
  background-color: #fff;
  position: relative;
  margin-bottom: 0.5em;
}

#carousel .shadow {
  -moz-box-shadow: 0px 16px 26px #888888;
  -webkit-box-shadow: 0px 16px 26px #888888;
  box-shadow: 0px 16px 26px #888888;
}

#carousel .slide {
  position: absolute;
  overflow: hidden;
}

#carousel .slide a:hover img {
  margin-top: 2px;
}

#carousel .slide img {
  width:  100%;
  height: 100%;
}

#carousel .slide p {
  position: relative;
  padding: 0;
  margin:  0;
  height:  100%
}

#carousel .slide span {
  background-color: #000;
  color: #fff;
  font-size: 0.8em;
  font-family: sans-serif;
  position: absolute;
  padding: 5px;
  width: 100%;
  bottom: 0;
  z-index: 99;
}

#carousel .navigate-left {
  cursor: pointer;
  position: absolute;
  bottom: 10px;
  left: 220px;
}

#carousel .navigate-right {
  cursor: pointer;
  position: absolute;
  bottom: 10px;
  right: 484px;
}


              
            
!

JS

              
                (function($) {
	$.fn.slidingCarousel = function (options) {
		options = $.extend({}, $.fn.slidingCarousel.defaults, options || {});

		var pluginData = {
			container: $(this),
			sinus:   [0],
			images:  null,
			mIndex:  null
		};

		var preload = function(callback) {
			var images = pluginData.container.find('.slide img'),
				total  = images.length,
				shift  = total % 2,
				middle = total < 3 ? total : ~~(total / 2) + shift,
				result = [],
				loaded = 0;

			images.each(function (index, element) {
				var img = new Image();

				$(img).bind('load error', function () {
					loaded++;

					// push loaded images into regular array.
					// to preserve the order array gets constructed so, that elements indexed:
					//
					//    0 1 2 3 4 5 6
					//
					// are shifted within destination array by half of total length (-1 depending on parity/oddness):
					//
					//    6 5 4 0 1 2 3
					//
					// and finally reversed to get correct scrolling direction.

					result[(index+middle-shift) % total] = element;

					// need ratio for calculating new widths
					element.ratio = this.width / this.height;
					element.origH = this.height;
					element.idx   = index;

					if (loaded == total) {
						pluginData.mIndex = middle;
						pluginData.sinsum = 0;
						pluginData.images = result.reverse();

						// prepare symetric sinus table

						for (var n=1, freq=0; n<total; n++) {
							pluginData.sinus[n] = (n<=middle) ? Math.sin(freq+=(1.6/middle)) : pluginData.sinus[total-n];

							if (n < middle)
								pluginData.sinsum += pluginData.sinus[n]*options.squeeze;
						}
						callback(pluginData.images);
					}
				});
				img.src = element.src;
			});
		};

		var setupCarousel = function() {
			preload(doLayout);
			setupEvents();
		};

		var setupEvents = function() {
			pluginData.container
				.find ('.slide p > a').click(function(e) {
					var idx = $(this).find('img')[0].idx,
						arr = pluginData.images;

					while (arr[pluginData.mIndex-1].idx != idx ) {
						arr.push(arr.shift());
					}
					doLayout(arr, true);
				})
				.end()
				.find('.navigate-right').click(function() {
					var images = pluginData.images;

					images.splice(0,0,images.pop());
					doLayout(images, true);
				})
				.end()
				.find('.navigate-left').click(function() {
					var images = pluginData.images;

					images.push(images.shift());
					doLayout(images, true);
				});
		};

		var doLayout = function(images, animate) {
			var mid  = pluginData.mIndex,
				sin  = pluginData.sinus,
				posx = 0,
				diff = 0,
				width  = images[mid-1].origH * images[mid-1].ratio,  /* width of middle picture */
				middle = (pluginData.container.width() - width)/2,   /* center of middle picture, relative to container */
				offset = middle - pluginData.sinsum,                 /* to get the center, all sinus offset that will be added below have to be substracted */
				height = images[mid-1].origH, top, left, idx, j=1;

			// hide description before doing layout
			pluginData.container.find('span').hide().css('opacity', 0);

			$.each(images, function(i, img) {
				idx = Math.abs(i+1-mid);
				top = idx * 15;

				// calculating new width and caching it for later use
				img.cWidth = (height-(top*2)) * img.ratio;

				diff = sin[i] * options.squeeze;
				left = posx += (i < mid) ? diff : images[i-1].cWidth + diff - img.cWidth;

				var el = $(img).closest('.slide'),
					fn = function() {
						if (i === mid-1) {
							// show caption gently
							el.find('span').show().animate({opacity: 0.7});
						}
					};
                    
				if (animate) {
					el.animate({
						height   : height - (top*2),
						zIndex   : mid-idx,
						top      : top,
						left     : left+offset,
						opacity  : i==mid-1 ? 1 : sin[j++]*0.8
					}, options.animate, fn);
				}
				else
				{
					el.css({
						zIndex   : mid-idx,
						height   : height - (top*2),
						top      : top,
						left     : left+offset,
						opacity  : 0
					}).show().animate({opacity: i==mid-1 ? 1 : sin[j++]*0.8 }, fn);

					if (options.shadow) {
						el.addClass('shadow');						
					}
				}
			});

			if (!animate) {
				pluginData.container
					.find('.navigate-left').css('left', middle+50)
					.end()
					.find('.navigate-right').css('left', middle+width-75);
			}
		};

		this.initialize = function () {
			setupCarousel();
		};

		// Initialize the plugin
		return this.initialize();

	};

	$.fn.slidingCarousel.defaults = {
		shadow: true,
		squeeze: 124,
		animate: 250
	};

})(jQuery);

              
            
!
999px

Console