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="lightbulb" class="off"></div>
<div id="container">
	<div id="message">Turn the lights on</div>
	<div id="btn-fix"></div>
</div>	

<div id="switch-container">
	<div id="switch-btn">
		<div id="switch-on"></div>
		<div id="switch-off" class="active"></div>
	</div>
</div>
              
            
!

CSS

              
                body
	background-color: #1C1C1C
	font-family: Arial, Helvetica

.bg-light-on
	background-color: #383838

.bg-light-flickering
	animation: flickering-light-bg 0.3s linear 1s infinite alternate

// LIGHT
#lightbulb
	position: absolute
	top: -50px
	left: 50%
	transform: translateX(-50%)
	width: 200px
	height: 200px
	border-radius: 50%

.flickering
	animation: flickering-light 0.3s linear 1s infinite alternate
	background: rgba(255,255,255,1)
	box-shadow: 0px 0px 10px rgba(255,255,255,1), 0px 0px 30px rgba(255,255,255,0.8), 0px 0px 50px rgba(255,255,255,0.6), 0px 0px 70px rgba(255,255,255,0.6), 0 0 120px rgba(255,255,255,0.4)

.on
	background: rgba(255,255,255,1)
	box-shadow: 0px 0px 10px rgba(255,255,255,1), 0px 0px 30px rgba(255,255,255,0.8), 0px 0px 50px rgba(255,255,255,0.6), 0px 0px 70px rgba(255,255,255,0.6), 0 0 120px rgba(255,255,255,0.4)


// LIGHT SWITCH
#container,
#switch-container

	text-align: center
	text-transform: uppercase
	color: rgba(255,255,255,0.5)
	padding: 20px

#container
	width: auto
	height: 100px
	position: absolute
	top: 50%
	left: 50%
	transform: translate(-50%, -50%)
	
	#message
		display: block
		position: relative
		margin: 0 0 10px 0
		letter-spacing: 2px

#switch-container
	top: 80%
	left: 50%
	transform: translateX(-50%)
	background-color: rgba(255,255,255,0.2)
	position: absolute
	margin: auto

#switch-btn
	background-color: #ccc
	width: 100px
	height: 50px
	margin: auto
	border-radius: 10px
	cursor: pointer

	#switch-on,
	#switch-off
		width: 48px
		height: 48px
		position: relative
		display: inline-block
		border: 1px solid rgba(0,0,0,0.1)
		text-shadow: 2px 0 0 #fff

		&.active
			background-color: #fff
			color: #ffc0cb
			text-shadow: 0 0 0 #fff
			cursor: default
			border-color: #fff

	#switch-on
		box-shadow: -5px 0px 0 #eee, -17px 0 5px rgba(0,0,0,0.2)
		border-radius: 10px 0 0 10px
		border-right: none
		float: left
		&:before
			content: "i"
			position: absolute
			top: 50%
			left: 50%
			transform: translate(-50%, -50%)
			color: #434343
		
		&.active
			box-shadow: -5px 0 0 #fff, -8px 0 3px rgba(0,0,0,0.3)
	
	#switch-off
		box-shadow: 5px 0px 0 #eee, 17px 0 5px rgba(0,0,0,0.2)
		border-radius: 0 10px 10px 0
		border-left: none
		float: right
		&:before
			content: "o"
			position: absolute
			top: 50%
			left: 50%
			transform: translate(-50%, -50%)
			color: #434343

		&.active
			box-shadow: 5px 0 0 #fff, 8px 0 2px rgba(0,0,0,0.3)
	
	
// FIX BTN
#btn-fix
	background-color: #ffc0cb
	width: 100px
	height: 50px
	margin: 20px auto
	border-radius: 10px
	cursor: pointer
	position: relative
	color: #fff
	font-weight: bold
	box-shadow: 0 5px 0 #c1919aff
	display: none
	
	&:active
		box-shadow: 0 3px 0 #c1919aff
		transform: translateY(2px)

	&:hover
		color: rgba(0,0,0,0.7)
		text-shadow: 1px 1px 0 rgba(255,255,255,0.7)

	&:before
		content: "fix it"
		position: absolute
		top: 50%
		left: 50%
		transform: translate(-50%, -50%)
	

// ANIMATION
@keyframes flickering-light
	0%, 50%
		background: rgba(255,255,255,1)
		box-shadow: 0px 0px 10px rgba(255,255,255,1), 0px 0px 30px rgba(255,255,255,0.8), 0px 0px 50px rgba(255,255,255,0.6), 0px 0px 70px rgba(255,255,255,0.6), 0 0 120px rgba(255,255,255,0.4)
	30%, 75%, 100%
		background: rgba(255,255,255,1)
		box-shadow: 0px 0px 10px rgba(255,255,255,1), 0px 0px 30px rgba(255,255,255,0.2), 0px 0px 50px rgba(255,255,255,0.1), 0px 0px 70px rgba(255,255,255,0.6), 0 0 90px rgba(255,255,255,0.01)

@keyframes flickering-light-bg
	0%, 50%
		background-color: #383838

	30%, 75%, 100%
		background-color: #1C1C1C
              
            
!

JS

              
                // TURN THE LIGHTS ON, EVENT
$( "#lightbulb" ).on( "light:on", function() {
	
	if ($(this).hasClass("flickering")) {
		
		$("body").removeClass("bg-light-flickering").addClass("bg-light-on");
		$(this).removeClass("flickering").addClass("on");
		message("There you go, much better!<br> You can turn the lights off now.", 1000);
		
	} else {
		
		$("body").addClass("bg-light-flickering");
		$(this).removeClass("off ").addClass("flickering");
		$("#btn-fix").hide().delay(4000).fadeIn(1000);
		message("Oops! Looks like the lightbulb is broken.", 2000);
	}
	
});

function message( text, delay ){
	$("#message").hide().delay(delay).fadeIn(1000).html(text)
}

// TURN THE LIGHTS OFF, EVENT
$( "#lightbulb" ).on( "light:off", function() {
	$("body").removeClass("bg-light-on");
	$(this).removeClass("on").addClass("off");
	message("Turn the lights on", 2000);
	
});

// FIX LIGHT, TRIGGER
$("#btn-fix").click( function() {
	$("#lightbulb").trigger("light:on");
	$(this).hide();
});

// LIGHT ON, TRIGGER
$("#switch-on").click(function(){
	if( !$(this).hasClass( "active" )) {
		$("#lightbulb").trigger("light:on");
		$(this).addClass("active");
		$("#switch-off").removeClass("active");
	}
});

// LIGHT OFF, TRIGGER
$("#switch-off").click(function(){
	if( !$(this).hasClass( "active" )) {
		$("#lightbulb").trigger("light:off");
		$(this).addClass("active");
		$("#switch-on").removeClass("active");	
	}
});

/* 

Same outcome as the two functions (triggers) above.
I tried to combine the two into a single and smarter one,
BUT I only made it longer and perhaps complicated things. Go me!

$("#switch-btn").click(function(event) {
	
	var switchID 		= $(event.target).attr('id');
	var switchState 	= $(event.target).attr('class');
	
	var trigger = "";
	var switch1 = "";
	var switch2 = "";
	
	if ( switchID == "switch-on" && switchState !== "active") {
		
		trigger = "light:on";
		switch1 = "#switch-on";
		switch2 = "#switch-off";
		
	} else if ( switchID == "switch-off" && switchState !== "active"){
		
		trigger = "light:off";
		switch1 = "#switch-off";
		switch2 = "#switch-on";
	}
	
	$("#lightbulb").trigger(trigger);
	$(switch1).addClass("active");
	$(switch2).removeClass("active");
	
});
*/
              
            
!
999px

Console