cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              - abc = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9'];
.frame
	.triggers
		-for val in abc
			input type='radio' name='morse' id='morse-#{val}' class="radio"
			label for='morse-#{val}' class="trigger" id="label-#{val}" #{val}
		.light
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Open+Sans:400);

$duration: 1.5s;

$characters: (
	a: '.-',
	b: '-...',
	c: '-.-.',
	d: '-..',
	e: '.',
	f: '..-.',
	g: '--.',
	h: '....',
	i: '..',
	j: '.---',
	k: '-.-',
	l: '.-..',
	m: '--',
	n: '-.',
	o: '---',
	p: '.--.',
	q: '--.-',
	r: '.-.',
	s: '...',
	t: '-',
	u: '..-',
	v: '...-',
	w: '.--',
	x: '-..-',
	y: '-.--',
	z: '--..',
	0: '-----',
	1: '.----',
	2: '..---',
	3: '...--',
	4: '....-',
	5: '.....',
	6: '-....',
	7: '--...',
	8: '---..',
	9: '----.',
);

@function lets-morse($string) {
	$morse-animations: ();
	$animation-name: '';
	@for $i from 1 through str-length($string) {
		$character  : str-slice($string, $i, $i); // slice string into single characters
		@if ($character == '.') {$animation-name: short-#{$i};} // assign animation name
		@if ($character == '-') {$animation-name: long-#{$i};} // assign animation name
		$animation: $animation-name $duration ( ($i - 1) * $duration); // create animation
		$morse-animations : append($morse-animations, $animation, comma); // combine animations
	}
	@return $morse-animations;
}

.frame {
	position: absolute;
	top: 50%;
	left: 50%;
	width: 400px;
	height: 400px;
	margin-top: -200px;
	margin-left: -200px;
	border-radius: 2px;
	box-shadow: 1px 2px 10px 0px rgba(0,0,0,0.3);
	overflow: hidden;
	background: #333;
	color: #fff;
	font-family: 'Open Sans', Helvetica, sans-serif;
	font-weight: 400;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}

.radio {
	display: none;
}

.triggers {
	position: absolute;
	bottom: 0;
	left: 0;
	background: #666;
	border-top: 2px solid #888;
	padding: 5px 0;
}

.trigger {
	position: relative;
	float: left;
	width: 34px;
	height: 34px;
	margin: 3px;
	font-size: 16px;
	line-height: 34px;
	text-align: center;
	text-transform: uppercase;
	border-radius: 50%;
	cursor: pointer;

	&:hover {
		background: #999;
	}
}

#label-0 {
	clear: both;
}

.light {
	position: absolute;
	width: 30px;
	height: 30px;
	top: -120px;
	left: 185px;
	border-radius: 50%;
	background: #fff;
	box-shadow: 0 0 15px 0 #fff;
	opacity: 0;
	animation: none;
}

#morse-c:checked ~ .light {
	animation: lets-morse( map-get($characters, c) );
}

@each $character, $code in $characters {
	#morse-#{$character}:checked ~ .light {
		animation: lets-morse( $code );
	}
}

// multiple animations to fix the error with same animations in a row
@for $i from 1 through 5 {
	@keyframes short-#{$i} {
		0%, 40%, 60%, 100% {
			opacity: 0;
		}
		41%, 59% {
			opacity: 1;
		}
	}

	@keyframes long-#{$i} {
		0%, 15%, 85%, 100% {
			opacity: 0;
		}
		16%, 84% {
			opacity: 1;
		}
	}	
}

            
          
!
999px
Loading ..................

Console