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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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

              
                <div id="panels">
  <img src="http://37.187.65.218/tom_www/public/images/gringo_avatar_tom.jpg">
	<img src="http://37.187.65.218/tom_www/public/images/gringo_avatar_marion.jpg">
	<img src="http://37.187.65.218/tom_www/public/images/gringo_avatar_tonton.jpg">
</div>
              
            
!

CSS

              
                #panels {
	width: 300px;
	height: 300px;
	background-color: white;
}

.panel {
	position: absolute;
}

.panel-right {
	position: absolute; 
}

.panel-left {
	position: absolute;
}
              
            
!

JS

              
                var NB_LINES = 10;
var NB_COLUMNS = 1;

var CURRENT_ROTATION = 0;
var IMAGES = [];
var NEXT_IMAGE = 1;

function getImages() {
	var images = $("#panels img");
	for (var i=0; i<images.length; i++) {
		var image = $(images[i]);
		IMAGES[i] = image.attr("src");
	}

	$("#panels").empty();
}

function panels() {
	// get dimensions from css
	var width = $("#panels").css("width").replace("px", "");
	var height = $("#panels").css("height").replace("px", "");

	// compute frame's dimensions
	var frameWidth = width / MY_VARIABLES.nbColumns;
	var frameHeight = height / MY_VARIABLES.nbLines;

	// for each line
	for (var i=0; i<MY_VARIABLES.nbLines; i++) {
		// create the div line
		var divLine = $("<div></div>").attr("id", "divLine"+i);
		divLine.attr("class", "line");
		$("#panels").append(divLine);
		// for each column
		for (var j=0; j<MY_VARIABLES.nbColumns; j++) {
			// create the div panel (for rotation)
			var divPanel = $("<div></div>");
			divPanel.attr("id", "panel-"+i+"-"+j);
			divPanel.attr("class", "panel");
			divPanel.css("margin-top", (i * frameHeight)+"px");
			divPanel.css("margin-left", (j * frameWidth)+"px");
			divPanel.css("width", frameWidth+"px");
			divPanel.css("height", frameHeight+"px");
			divLine.append(divPanel);

			// create the div left
			var divLeft = $("<div></div>");
			divLeft.attr("id", "panel-left-"+i+"-"+j);
			divLeft.attr("class", "panel-left");
			divLeft.css("width", "0px");
			divLeft.css("height", frameHeight+"px");
			//divLeft.css("margin-left", (frameWidth * -1)+"px");
			divLeft.css("background-position", (j * -frameWidth)+"px "+(i * -frameHeight)+"px");
			divPanel.append(divLeft);

			// create the div right
			var divRight = $("<div></div>");
			divRight.attr("id", "panel-right-"+i+"-"+j);
			divRight.attr("class", "panel-right");
			divRight.css("width", frameWidth+"px");
			divRight.css("height", frameHeight+"px");
			divRight.css("background-position", (j * -frameWidth)+"px "+(i * -frameHeight)+"px");
			divPanel.append(divRight);
		}
	}
}

function slideLeft() {
	var width = $("#panels").css("width").replace("px", "");
	var frameWidth = width / MY_VARIABLES.nbColumns;

	var panels = $(".panel");
	for (var i=0; i<panels.length; i++) {
		var id = $(panels[i]).attr("id");
		var panelLeft = $("#"+id+" .panel-left");
		var panelRight = $("#"+id+" .panel-right");

		var time = MY_VARIABLES.timeBeforeSlide;
		if (MY_VARIABLES.randomTimeForSlide == true) {
			time = time * 0.25 + time * 0.75 * Math.random();
		}

		panelLeft.animate({"width" : frameWidth+"px"}, time);
		panelRight.animate({"width" : "0px", "margin-left" : frameWidth+"px"}, time);

	}

	setTimeout(function() {
		NEXT_IMAGE++;
		if (NEXT_IMAGE >= IMAGES.length) {
			NEXT_IMAGE = 0;
		}
		$(".panel-right").css("background-image", "url('"+IMAGES[NEXT_IMAGE]+"')");
	}, MY_VARIABLES.timeBeforeSlide);

	setTimeout("slideRight()", MY_VARIABLES.displayDuration);
}

function slideRight() {
	var width = $("#panels").css("width").replace("px", "");
	var frameWidth = width / MY_VARIABLES.nbColumns;

	var panels = $(".panel");
	for (var i=0; i<panels.length; i++) {
		var id = $(panels[i]).attr("id");
		var panelLeft = $("#"+id+" .panel-left");
		var panelRight = $("#"+id+" .panel-right");

		var time = MY_VARIABLES.timeBeforeSlide;
		if (MY_VARIABLES.randomTimeForSlide == true) {
			time = time * 0.25 + time * 0.75 * Math.random();
		}

		panelLeft.animate({"width" : "0px"}, time);
		panelRight.animate({"width" : frameWidth+"px", "margin-left" : "0px"}, time);

	}

	setTimeout(function() {
		NEXT_IMAGE++;
		if (NEXT_IMAGE >= IMAGES.length) {
			NEXT_IMAGE = 0;
		}
		$(".panel-left").css("background-image", "url('"+IMAGES[NEXT_IMAGE]+"')");
	}, MY_VARIABLES.timeBeforeSlide);

	setTimeout("slideLeft()", MY_VARIABLES.displayDuration);
}

// call the scroll at regular time
function galery() {
	setTimeout("slideLeft()", MY_VARIABLES.displayDuration);
}

function refresh() {
	NEXT_IMAGE = 1;

	$(".panel-right").css("background-image", "url('"+IMAGES[0]+"')");
	$(".panel-left").css("background-image", "url('"+IMAGES[1]+"')");

	$("#panels").empty();
	panels();
}

var Variables = function() {
	this.displayDuration = 3000;
	this.timeBeforeSlide = 2000;
	this.randomTimeForSlide = true;

	this.nbLines = 3;
	this.nbColumns = 3;

	this.refresh = function() { refresh(); };
};

var MY_VARIABLES = new Variables();

window.onload = function() {
	var gui = new dat.GUI();

	var fTime = gui.addFolder('Time');
	fTime.add(MY_VARIABLES, 'displayDuration', 1, 10000).step(10);
	fTime.add(MY_VARIABLES, 'timeBeforeSlide', 1, 5000).step(10);
	fTime.add(MY_VARIABLES, 'randomTimeForSlide');

	fTime.open();

	var fPanels = gui.addFolder('Panels');

	fPanels.add(MY_VARIABLES, 'nbLines', 1, 100).step(1);
	fPanels.add(MY_VARIABLES, 'nbColumns', 1, 100).step(1);
	fPanels.add(MY_VARIABLES, 'refresh');

	fPanels.open();

	// get images
	getImages();

	// create panels
	panels();

	// init backgrounds
	$(".panel-right").css("background-image", "url('"+IMAGES[0]+"')");
	console.log($(".panel-right").css("background-image"));
	$(".panel-left").css("background-image", "url('"+IMAGES[1]+"')");

	// launch the galery
	galery();
};
              
            
!
999px

Console