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

Auto Save

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

              
                	<main>
		<div id="switch-container">
			<button id="switch" class="switch-off">OFF</button>
		</div>
	</main>

	<!-- Link to jquery -->
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>

	<script src="js/switch.js"></script>
              
            
!

CSS

              
                /* base background colour */
body {
	background: #000;
	transition: background-color 0.50s ease 0s;
}
 /* switch on background colour */
.body-on {
	background: #fff;
}

#switch-container {
	width: 500px;
	height: 250px;
	margin-right: auto;
	margin-left: auto;
	border: none;
	/* default (off) button color */
	background: #2C3E50;
	/* set up background animation */
	transition: background-color 0.50s ease 0s;
}

#switch {
	height: 250px;
	width: 250px;
	border: none;
	outline: none;
	font-size: 100px;
	font-family: 'Open Sans', sans-serif;
	font-weight: 300;
	color: #ECF0F1;

	/* Set up the animation properties */
   transition: transform 0.25s linear 0s,
   		background 0.25s ease 0s,
		border-radius 0.25s ease 0s,
		box-shadow 0.25s ease 0s;
}

.switch-off {
	transform: translateX(0px);
	background: #E74C3C;
	border-radius: 0 50% 50% 0;
	box-shadow: 7px 0px 8px -4px rgba(0,0,0,0.54);
}

.switch-on {
	transform: translateX(250px);
	background: #96CA2D;
	border-radius: 50% 0 0 50%;
	box-shadow: -7px 0px 8px -4px rgba(0,0,0,0.54);
}

/* background colour for on */
#switch-container.background-on {
	background: #2980B9;
}
              
            
!

JS

              
                $(document).ready(function() {
	// when the switch is clicked...
  function switchOff() {
    $('.switch-off').on('click', function() {
      // change off class to on
      $(this).removeClass('switch-off');
      $(this).addClass('switch-on');
      // change the button text
      $(this).html('ON');
      // change switch container background color to 'on';
      $('#switch-container').addClass('background-on');
      //change body background color
      $('body').addClass('body-on');
      // call the switchOn function which will fire up the event listener for the on button
      switchOn();
    });
  }
  
  function switchOn() {
    $('.switch-on').on('click', function() {
      $(this).removeClass('switch-on');
      $(this).addClass('switch-off');
      $(this).html('OFF');
      $('#switch-container').removeClass('background-on');
      $('body').removeClass('body-on');
      switchOff();
    });
  }
  // when the document is ready, call the switchOff function
  switchOff();
	
});
              
            
!
999px

Console