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. 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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                
              
            
!

CSS

              
                html,body {
	margin:0;
	padding:0;

}
body > div {
	width:33.33%;
	position:relative;
	float:left;
	min-height:1em;
}
div > div {
	width:100%;
	height:50px;
	outline:1px solid black;
	background:rgba(196,196,196,1);
	position:absolute;
}
              
            
!

JS

              
                // No animation completion handlers are used.
// Left column rows do not get removed, and perform as buttons.
// Middle column rows are instantly set to display:none, with a display:block animation to bring them back while the opacity fades.
// Right column children are animated as a mathematical set, relatively, with the requirement that elements get sorted.
// For instance to animate from elements A-B-C-D to A-B-D, old minus new leaves just C, then added to the non-animated value leaves A-B-D-C, which is then sorted. At each animation frame, children are diffed using the animated value.

// Now with Mithril! 

var duration = 1.0;

var data = [
	{name: "zero", id: 0},
	{name: "one", id: 1},
	{name: "two", id: 2},
	{name: "three", id: 3},
	{name: "four", id: 4},
	{name: "five", id: 5},
	{name: "six", id: 6},
	{name: "seven", id: 7}
];

// Shoe does not yet support CSS non-numeric type properties so I implement them here.
// For additive and relative, would also need to implement add, subtract, and zero
function DisplayStringType(settings) {
	Shoe.ValueType.call(this,settings);
}
DisplayStringType.prototype = Object.create(Shoe.ValueType.prototype);
DisplayStringType.prototype.constructor = DisplayStringType;
DisplayStringType.prototype.interpolate = function(a,b,progress) {
	if (progress >= 1) return b;
	return a;
};

function Item(datum) {
	Shoe.Layer.call(this);
	
	this.name = datum.name;
	this.id = datum.id;
	this.visible = true;
	
	this.y = 0;
	this.registerAnimatableProperty("y",new Shoe.NumberType({
		duration: duration
	}));
	
	this.opacity = 1;
	this.registerAnimatableProperty("opacity",new Shoe.NumberType({
		duration:duration
	}));
	
	this.level = 196;
	this.registerAnimatableProperty("level",new Shoe.NumberType({
		duration:duration
	}));
	
	this.display = "block";
	this.registerAnimatableProperty("display",new DisplayStringType({
		duration: duration,
		from: "block",
		to: "block",
		blend: "absolute",
		additive: false
	}));
	
	this.toggle = function() {
		this.visible = !this.visible;
		m.redraw.strategy("none"); // Mithril-Shoe glue
		if (this.visible) { // triggers animation!
			this.opacity = 1;
			this.level = 196;
			this.display = "block";
		} else { // triggers animation!
			this.opacity = 0;
			this.level = 255;
			this.display = "none";
		}
	}
	
	this.render = function() {
		m.redraw(true); // Mithril-Shoe glue
	}
}

var Buttons = { // left
	view: function(ctrl, args) {
		return m("div", [
			args.items.map(function(item) {
				var level = Math.round(item.level); // animated values are provided!
				var style = {
					position:"relative",
					backgroundColor:"rgb("+level+","+level+","+level+")"
				};
				var mouseDown = function(e) {
					args.toggle(item);
				}
				return m("div", {style: style, onmousedown: mouseDown}, item.name);
			})
		])
	}
}

var Hide = { // middle
	view: function(ctrl, args) {
		return m("div", [
			args.items.map(function(item) {
				var mouseDown = function(e) {
					args.toggle(item);
				};
				var transform = "translate3d(0,"+item.y+"px,0)"; // animated values are provided!
				var style = {
					display: item.display, // animated values are provided!
					opacity: item.opacity, // animated values are provided!
					webkitTransform: transform,
					transform: transform
				}
				return m("div", {style: style, onmousedown: mouseDown}, item.name);
			})
		])
	}
}

var Remove = { // right
	view: function(ctrl, args) {
		var array = args.items;
		return m("div", [
			array.map(function(item) {
				var transform = "translate3d(0,"+item.y+"px,0)"; // animated values are provided!
				var style = {
					opacity: item.opacity, // animated values are provided!
					webkitTransform: transform,
					transform: transform
				};
				var mouseDown = function(e) {
					args.toggle(item);
				};
				return m("div", {style: style, onmousedown: mouseDown}, item.name);
			})
		])
	}
}

function App(data) {
	Shoe.Layer.call(this);
	
	this.allItems = data.map( function(datum) {
		return new Item(datum);
	});
	
	this.visibleItems = this.allItems.slice(0);
	this.registerAnimatableProperty("visibleItems", new Shoe.SetType({
		duration: duration,
		sort: function(a,b) {
			return a.id - b.id;
		}
	}));
	
	this.toggle = function(item) {
		item.toggle();
		this.layout();
	};
	
	this.layout = function() {
		var height = 50;
		var y = 0;
		m.redraw.strategy("none"); // Mithril-Shoe glue
		this.allItems.forEach( function(item) {
			item.y = y; // triggers animation!
			if (item.visible) y += height;
		});
		this.visibleItems = this.allItems.filter( function(item) { // triggers animation!
			return item.visible;
		});
	};
	
	this.render = function() {
		m.redraw(true); // Mithril-Shoe glue
	};
	
	this.view = function() {
		var toggle = this.toggle.bind(this);
		var allItems = this.allItems;
		var visibleItems = this.visibleItems; // animated values are provided!
		return [
			m.component(Buttons, {items: allItems, toggle:toggle}),
			m.component(Hide, {items: allItems, toggle:toggle}),
			m.component(Remove, {items: visibleItems, toggle:toggle})
		]
	}
	
	Shoe.disableAnimation(true);
	this.layout();
}

var app = new App(data);
m.mount(document.body, app);
              
            
!
999px

Console