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

              
                <div class="full center">
	<button onclick="virConsole.reset()">Reset Log</button>
</div>
<div class="left">
	<div class="half center" draggable="true">This is a draggable element</div>
	<div class="miscWrapper full">
		<button class="quarter">Button</button>
		<input class="quarter" type="text" placeholder="I'm a text field!" />
		<input type="file" />
	</div>
	<div class="full"><textarea class="full">I'm a TextArea element. Try selecting text inside to see the "select" event fire!</textarea></div>
	<form class="demoForm full" action="" method="get" onsubmit="return false">
		<div style="width:100%; text-align: center">I'm a demo form! Try submitting to see event!</div>
		<input type="number" placeholder="20" />
		<input type="range" />
		<div>Checkbox: <input type="checkbox" /></div>
		<div>Radio elems: <input type="radio" name="group" /><input type="radio" name="group" /></div>
		<div class="full center">
			<input type="reset" />
			<input type="submit" value="submit form!" style="background-color: greenyellow; padding: 10px; font-size: 1.2rem;" />
		</div>
	</form>
	<div class="videoWrapper full">
		<div class="full center">This is a video element! Try playing, changing volume, etc. to see events!</div>
		<video  class="full" controls src="https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4"
			   poster="https://peach.blender.org/wp-content/uploads/title_anouncement.jpg?x11217">

		</video>
	</div>
</div>
<div class="right">
	<div class="console">
		<div class="row">Event Log:</div>
	</div>
	<div class="evtCounter">
		<div class="count"><span class="countInt">0</span> events</div>
	</div>
</div>
              
            
!

CSS

              
                .full {
	width: 100%;
	margin-bottom: 8px;
}
.half {
	width: 49%;
}
.quarter {
	width: 24%;
}
.center {
	text-align: center;
	margin-left: auto;
	margin-right: auto;
}
.left,.right {
	width: 45%;
	min-height: 300px;
	border: 1px dashed black;
	padding: 5px;
	margin-left: 1%;
	float: left;
}
.console {
	padding: 10px;
	background-color: black;
	color: greenyellow;
	font-family: monospace;
	border-radius: 8px;
	overflow-y: scroll;
	height: 300px;
	margin-bottom: 10px;
}
.demoForm,.videoWrapper {
	border: 3px double black;
	margin: 10px;
	padding: 10px;
}
.left > * {
	margin-top: 8px;
}
.left .full {
	width: 90%;
	margin-left: 4%;
}
.left .half, .left .quarter {
	border: 1px solid black;
	padding: 2px;
	margin-left: auto;
	margin-right: auto;
	/* display: inline-block; */
	/* margin-right: 4px; */
}
button {
	font-size: 1.2rem;
}
.right {
	position: relative;
}
.evtCounter {
	position: absolute;
	top: 10px;
	right: 30px;
	padding: 10px;
	background-color:rgba(255, 255, 255, 0.8);
	border-radius: 20px;
}
              
            
!

JS

              
                window.virConsole = {
	evtCount : 0,
	updateCounterElem(){
		document.querySelector(".countInt").innerText = this.evtCount.toString();
	},
	getElem : function(){
		return document.querySelector(".console");
	},
	reset : function(){
		this.getElem().innerHTML = "";
		this.logMsg("Event Log:");
		this.evtCount = 0;
		this.updateCounterElem();
	},
	createRowElem : function(text){
		var row = document.createElement("div");
		row.classList.add("row");
		row.innerText = text;
		return row;
	},
	simplifyJsEventObj : function(evt){
		return {
			type : evt.type,
			srcElement : evt.srcElement.outerHTML,
			target : evt.target.outerHTML,
			bubbles : evt.bubbles
		}
	},
	autoScroll : function(){
		var console = this.getElem();
		console.scrollTo(0,console.scrollHeight);
	},
	logMsg: function(text){
		this.getElem().appendChild(this.createRowElem(text));
	},
	logEvent : function(evt){
		var evtText = JSON.stringify(this.simplifyJsEventObj(evt),null,4);
		var evtText = "Fired @" + (new Date()).getTime() + " || " +  "Event Type: " + evt.type.toString();
		this.evtCount++;
		this.updateCounterElem();
		this.getElem().appendChild(this.createRowElem(evtText));
		this.autoScroll();
	}
}

// https://gist.github.com/PaulKinlan/45de2fb55c1390d871b3a67f72ae730c
function monitorEvents(element,cb) {
	var log = typeof(cb) === "function" ? cb : function(e) { console.log(e);};
	var events = [];
	for(var i in element) {
		if(i.startsWith("on")) events.push(i.substr(2));
	}
	events.forEach(function(eventName) { 
		element.addEventListener(eventName, log); 
	}); 
}

window.distributeEvent = function(evt){
	console.log(evt);
	virConsole.logEvent(evt);
}
monitorEvents(document.querySelector(".left"),function(evt){
	distributeEvent(evt);
});
// Since video events don't bubble by default, capture separately
var mediaEventStrings = ["audioprocess", "canplay", "canplaythrough", "complete", "durationchange", "emptied", "ended", "loadeddata", "loadedmetadata", "pause", "play", "playing", "ratechange", "seeked", "seeking", "stalled", "suspend", "timeupdate", "volumechange", "waiting"];
document.querySelectorAll("video").forEach(function(elem){
	mediaEventStrings.forEach(function(evtString){
		elem.addEventListener(evtString,function(evt){
			distributeEvent(evt);
		});
	});
});
// Add page load events
window.addEventListener('load',distributeEvent);
// Lazy css alternative - set equal height columns
var left = document.querySelector(".left");
var right = document.querySelector(".right");
var maxHeight = getComputedStyle(left).height > getComputedStyle(right).height ? getComputedStyle(left).height : getComputedStyle(right).height;
left.style.minHeight = maxHeight;
right.style.minHeight = maxHeight;
virConsole.getElem().style.height = maxHeight;
              
            
!
999px

Console