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

              
                <meta name="viewport" content="width=device-width, initial-scale=1.0">

<div class="container">
	<h1>Switches</h1>
	<div class="row">
			<span>No color</span>
			<div class="material-switch active">
	</div>
	</div>
	<div class="row">
			<span>Danger</span>
			<div class="material-switch red active"></div>
	</div>
	<div class="row">
			<span>Success</span>
			<div class="material-switch green active"></div>
	</div>
	<div class="row">
			<span>Primary</span>
			<div class="material-switch blue active"></div>
	</div>
	<div class="row">
			<span>Warning</span>
			<div class="material-switch yellow active"></div>
	</div>
	<div class="row">
			<span>Default</span>
			<div class="material-switch default active"></div>
	</div>
</div>

<span id="credits">
	<i class="mdi mdi-xml"></i>
	with
	<i class="mdi mdi-heart"></i>
	by
	<a href="https://codepen.io/GuiCavi/" target="_blank">
		<i class="mdi mdi-codepen"></i>
	</a>
</span>
              
            
!

CSS

              
                @import compass

@import url(https://fonts.googleapis.com/css?family=RobotoDraft)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$red: #db4437
$blue: #4285f4
$yellow: #f4b400
$green: #0f9d58
$default: #e7e6dd
$color-theme: ("red": $red, "green": $green, "blue": $blue, "yellow": $yellow, "default": $default)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@mixin dim($width, $height:$width)
	width: $width
	height: $height
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@function unpack($shorthand)
	@if length($shorthand) == 1
		@return nth($shorthand, 1) nth($shorthand, 1) nth($shorthand, 1) nth($shorthand, 1)
	@else if length($shorthand) == 2
		@return nth($shorthand, 1) nth($shorthand, 2) nth($shorthand, 1) nth($shorthand, 2)
	@else if length($shorthand) == 3
		@return nth($shorthand, 1) nth($shorthand, 2) nth($shorthand, 3) nth($shorthand, 2)
	@else
		@return $shorthand
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@mixin pos($position: relative, $coordinates: null null null null)
	@if type-of($position) == list
		$coordinates: $position
		$position: relative

	$coordinates: unpack($coordinates)

	$offsets: (top: nth($coordinates, 1), right: nth($coordinates, 2), bottom: nth($coordinates, 3), left: nth($coordinates, 4))

	position: $position

	@each $offset, $value in $offsets
		@if is-length($value)
			#{$offset}: $value
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*
	+box-sizing(border-box)
	&:before, &:after
		+box-sizing(border-box)
		
html
	height: 100%

body
	min-height: 100%
	font-family: 'Roboto', sans-serif
	background-color: #123456
	display: flex
	align-items: center
	justify-content: center

svg[hidden]:not(:root)
	display: none
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@mixin switch-colors
	@each $theme, $color in $color-theme
		.material-switch.active.#{$theme}
			.bar, .ripple
				background-color: rgba($color, 0.5)
			.thumb::before
				background-color: $color
////////////////////////////////////////////////////////////////////////
////////////////////
////////////////////////////////////////////////////////////////////////
.material-switch
	position: relative
	display: inline-block
	vertical-align: middle
	cursor: pointer
	+dim(36px, 24px)
	&.active
		.bar
			background-color: rgba(158, 158, 158, 0.5)
		.thumb-container
			+transform(translate(100%, 0))
		.thumb::before
			background-color: #9E9E9E
		.ripple
			+animation(switchRipple 0.5s cubic-bezier(0.35, 0, 0.25, 1))
	.bar
		background-color: #9E9E9E
		+pos(absolute, 5px null null 1px)
		+dim(34px, 14px)
		+border-radius(8px)
		+transition(all 0.5s cubic-bezier(0.35, 0, 0.25, 1))
	.thumb-container
		width: 16px
		z-index: 1
		+pos(absolute, 2px null null 0)
		+transition(all 0.5s cubic-bezier(0.35, 0, 0.25, 1))
		+transform(translate(0,0))
	.thumb
		+dim(20px)
		&::before
			content: ""
			position: absolute
			display: block
			background-color: #FAFAFA
			+dim(20px)
			+border-radius(50%)
			+box-shadow(0px 2px 5px 0 rgba(0, 0, 0, 0.26))
			+transition(all 0.5s cubic-bezier(0.35, 0, 0.25, 1))
	.ripple
		background-color: rgba(0,0,0,0.2)
		+pos(absolute, 50% null null 50%)
		+dim(48px)
		+transform(translate(-50%, -50%) scale(0))
		+border-radius(50%)
		+transition(all 0.5s cubic-bezier(0.35, 0, 0.25, 1))
////////////////////////////////////////////////////////////////////////
////////////////////
////////////////////////////////////////////////////////////////////////
+keyframes(switchRipple)
	0%
		opacity: 0
		+transform(translate(-50%, -50%) scale(0))
	50%
		opacity: 0.67
	75%
		opacity: 0.1
		+transform(translate(-50%, -50%) scale(1))
	100%
		opacity: 0
////////////////////////////////////////////////////////////////////////
////////////////////
////////////////////////////////////////////////////////////////////////
+switch-colors()
////////////////////////////////////////////////////////////////////////
////////////////////
////////////////////////////////////////////////////////////////////////
.container
	padding: 20px
	background-color: #343434
	width: 300px
	+box-shadow(0px 1px 2px #000)

h1
	text-align: center
	color: #f0f0f0
	font-weight: bold
	margin: 0 0 15px
	font-size: 26px
	letter-spacing: 3px

.row
	&:not(:last-child)
		margin-bottom: 10px
	&::after
		content: ""
		display: block
		clear: both
	span
		color: #f0f0f0
		float: left
	.material-switch
		float: right		

#credits
	+text-shadow(1px 1px 2px #222)
	position: fixed
	bottom: 10px
	right: 10px
	font-size: 14px
	line-height: 1.8
	color: #fff
	i.mdi
		font-size: 28px
		vertical-align: middle
		margin: 0 10px
		&.mdi-heart
			color: #FF432F
		&.mdi-codepen
			color: #2AE052
		&.mdi-xml
			color: #FFE02F
              
            
!

JS

              
                var switchClick = function(e) {
	$(this).toggleClass('active');
};

(function($) {	
	$.fn.materialSwitch = function(options) {		
		this.each(function() {
			$(this).click(switchClick);
			
			$('<div class="bar" />').appendTo($(this));
			$('<div class="thumb-container" />').append(
				$('<div class="thumb" />').append(
					$('<div class="ripple"/>')
				)
			).appendTo($(this));
		});
		return this;
	};
	
	$('.material-switch').materialSwitch();

}(jQuery));
              
            
!
999px

Console