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

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="wrapper" style="width:100%;height:100%;">

</div>
              
            
!

CSS

              
                html, body {
	overflow: hidden;
	height: 100%;
}
.instance {
	position: relative;
	width: 100%;
	height: 100%;
}

.bar {
	position: absolute;
	top: 0;
	left: 0;
	z-index:999;
}

.handle {
	position: absolute;
	top: 0;
	left: 0;
}
.one {
	position:absolute;
	left:0;
	top:0;
}
.two {
	position:absolute;
	right:0;
	bottom:0;
}
              
            
!

JS

              
                /*
Title: Sliding Windows Web UI
Author: Michael Alex Morley-Clarke
Filename: UI.js
Last updated: 13/01/2017
Description:	Two content windows are drawn, split down the middle by a bar which can be dragged, changing the split ratio between the two windows. 
				The orientation of the page changes automatically with the media orientation. 
				Instances of this UI can be embedded within each other and the orientation of these are updated as the bar is dragged.
*/

$(document).ready(function(){
	addWindow($("#wrapper"));
	addWindow($("#wrapper").children().eq(0).children().eq(0));
	addWindow($("#wrapper").children().eq(0).children().eq(2));
	
});

function addWindow(e){
	var init;
	appendCode(e);
	init=e.children().eq(0);
	setOrientation(init);
	setDraggable(init);
	setBarPos(init);
	setHandle(init);
	setWindowRatio(init);
}

//on start up
function appendCode(e){
	e.append('<div class="instance" orientation="landscape"><div class="one w3-blue"></div><div class="bar" percent="50"><div class="handle w3-black"></div></div><div class="two w3-grey"></div></div>');
}

function setOrientation(e){
	if(e.width()>e.height()){
		e.attr("orientation","landscape");
	}else{
		e.attr("orientation","portrait");
	}
}

function setDraggable(e){
	var bar=e.children().eq(1);
	Draggable.create(bar,{
		type:"x,y",
		bounds:e,
		trigger:bar.children().eq(0),
		onDrag:function(){
			setPercent(e);
			resizeAll();
		}
	});
}

function setBarPos(e){
	var	bar=e.children().eq(1), 
		percent=parseFloat(bar.attr("percent"));
	if(isLandscape(e)){
		TweenMax.set(bar,{x:e.width()*percent/100,y:0,width:0,height:"100%"});
	}else{
		TweenMax.set(bar,{y:e.height()*percent/100,x:0,width:"100%",height:0});
	}
}

function setHandle(e){
	var handle=e.children().eq(1).children();
	if(isLandscape(e)){
		TweenMax.set(handle,{width:40,height:e.height(),xPercent:-50,yPercent:0});
	} else {
		TweenMax.set(handle,{width:e.width(),height:40,xPercent:0,yPercent:-50});
	}
}

function setWindowRatio(e){
	var 	one=e.children().eq(0),two=e.children().eq(2),
		percent=getPercent(e.children().eq(1));
	if(isLandscape(e)){
		TweenMax.set(one,{height:"100%",width:percent+"%"});
		TweenMax.set(two,{height:"100%",width:100-percent+"%"});
	}else{
		TweenMax.set(one,{width:"100%",height:percent+"%"});
		TweenMax.set(two,{width:"100%",height:100-percent+"%"});
	}
}
  
//on drag
function setPercent(e){
	var 	bar=e.children().eq(1),
		draggable=Draggable.get(bar);
	if(isLandscape(e)){
		bar.attr("percent",draggable.x*100/e.width());
	}else{
		bar.attr("percent",draggable.y*100/e.height());
	}
}
  
//sub functions
function isLandscape(e){
	if(e.attr("orientation")=="landscape"){
		return true;
	}else{
		return false;
	}
}

function getPercent(e){
	return parseFloat(e.attr("percent"));
}

//update functions
function setPercent(e){
	var 	bar=e.children().eq(1),
		draggable=Draggable.get(bar);
	if(isLandscape(e)){
		bar.attr("percent",draggable.x*100/e.width());
	}else{
		bar.attr("percent",draggable.y*100/e.height());
	}
}

$(window).resize(function(){
	resizeAll();
});

function resizeAll(){
	$(".instance").each(function(){
		setOrientation($(this));
		setBarPos($(this));
		setHandle($(this));
		setWindowRatio($(this));
		/* #SOON ... closeCheck($(this)); */
	});
}

//add + removing windows

function closeCheck(e){
	var 	bar=e.children().eq(1),
		draggable=Draggable.get(bar);
	if(isLandscape(e)){
		if(e.children().eq(0).width()<=20){
			disableDraggable(e);
		}
		if(e.children().eq(2).width()<=20){
			disableDraggable(e);
			
		}
	}else{
		if(e.children().eq(0).height()<=20){
			disableDraggable(e);
		}
		if(e.children().eq(2).height()<=20){
			disableDraggable(e);
			
		}
	}
}

function disableDraggable(e){
	var 	bar=e.children().eq(1),
		draggable=Draggable.get(bar);	
	draggable.disable();
	TweenMax.to(bar,0.2,{x:-40});
	bar.on("click",enableDraggable(e));
}

function enableDraggable(e){
	var 	bar=e.children().eq(1),
		draggable=Draggable.get(bar);	
	bar.attr("percent","50");
	setBarPos(e);
	setHandle(e);
	setWindowRatio(e);
	draggable.enable();
	bar.off("click");
}
              
            
!
999px

Console