cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv


A Pen By Captain Anonymous

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

		<meta charset="utf-8">
		<title>Slider jQuery</title>

		<div class="slider" id="slider">
			<div class="slider-content">
				<div class="slide"><img src="http://lorempicsum.com/nemo/627/300/1" alt="Slide 1"></div>
				<div class="slide"><img src="http://lorempicsum.com/nemo/627/300/2" alt="Slide 2"></div>
				<div class="slide"><img src="http://lorempicsum.com/nemo/627/300/3" alt="Slide 3"></div>
				<div class="slide"><img src="http://lorempicsum.com/nemo/627/300/4" alt="Slide 4"></div>
              * {
	position: relative;
	margin: 0;
	padding: 0;

body {
	text-align: center;

.slider {
	margin: 20px auto;
	width: 627px;
	overflow: hidden;
.slider-content {
	width: 2508px; /* 627px * 4 */
.slide {
	float: left;
	width: 627px;
              $(document).ready(function() {
	var slider = $('#slider');
	var slider_content = slider.children('.slider-content');

	slider.on('click', function(e) {
	// Fonction pour changer de slider
	function slide() {

		// On récupère le slide actuellement affiché
		var current_slide = slider_content.children('.slide.active');

		// Si aucun slide n'a de classe active, on prend le premier par défaut
		if (!current_slide.length) {
			current_slide = slider_content.children('.slide:first');

		// On définit le nouveau slide à afficher
		var new_slide = current_slide.next();
		if (!new_slide.length) {
			new_slide = slider_content.children('.slide:first');

		if (new_slide && new_slide.length) {

			// On anime le slide pour afficher le nouveau
			slider_content.animate({ left: -new_slide.position().left }, 250, function() {
				current_slide.removeClass('active'); // On retire la classe active à l'ancien slide
				new_slide.addClass('active'); // On ajoute la classe active au nouveau slide



🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................