css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>

<link rel="stylesheet" href="https://cdn.rawgit.com/bgrins/spectrum/master/spectrum.css">
<script src="https://cdn.rawgit.com/bgrins/spectrum/master/spectrum.js"></script>

<button class="addEmptyKeyframe" onclick="addEmptyKeyframe()">Add Empty Keyframe</button>
<button class="save" onclick="save()">Save</button>


<div class="keyframesContainer">
	<div class="singleKeyframeContainer emptyKeyframeContainer hidden">
		<button class="deleteKeyframe" onclick="deleteKeyframe($(this).closest('.singleKeyframeContainer'))">X</button>
		<br>
		<button class="copyToNewKeyframe" onclick="copyToNewKeyframe($(this).closest('.singleKeyframeContainer'))">Copy To New Keyframe</button>
		<div class="timeContainer">
			<label for="time">Time: </label>
			<input type="number" name="time" class="timeInput" value="0"> seconds</input>
		</div>
		<label for="transition">Transition: </label>
		<select class="transition">
	<option>instantaneous</option>
	<option>fade</option>	
</select>
		<ul class="strip">
		</ul>
		<button class="addLight" onclick="addLightTo($(this).prev('.strip'))">Add Light</button>
	</div>
	<div class="singleKeyframeContainer">
		<button class="deleteKeyframe" onclick="deleteKeyframe($(this).closest('.singleKeyframeContainer'))">X</button>
		<br>
		<button class="copyToNewKeyframe" onclick="copyToNewKeyframe($(this).closest('.singleKeyframeContainer'))">Copy To New Keyframe</button>
		<div class="timeContainer">
			<label for="time">Time: </label>
			<input type="number" name="time" class="timeInput" value="0"> seconds</input>
		</div>
		<label for="transition">Transition: </label>
		<select class="transition">
	<option>instantaneous</option>
	<option>fade</option>	
</select>
		<ul class="strip">
		</ul>
		<button class="addLight" onclick="addLightTo($(this).prev('.strip'))">Add Light</button>
	</div>
</div>
<!-- <button class="clearSwatches" onclick="clearSwatches()">Clear Saved Color Swatches</button> -->
            
          
!
            
              $light-color: red;
$string-green: #035C2A;

* {
	// outline: blue solid thin;
	box-sizing: border-box;
}
body {
	background-color: black;
	overflow-x: scroll;
}

.hidden {
	display: none;
}

.keyframesContainer {
  flex-wrap: nowrap;
}
.singleKeyframeContainer {
	// display: flex;
	float: left;
	border: 1px solid $string-green;
	margin: 5px;
	padding: 10px;
}

.deleteKeyframe {
	float: right;
	margin-left: 100%;
}

button {
	margin: 5px auto;
}

.timeContainer {
	display: block;
	color: white;
}

label {
	color: white;
}

.timeInput {
	width: 5em;
}

ul {
	margin-left: 10px;
	list-style-type: none;
	padding: 0px;
	border-left: #035C2A 15px solid;
}
.light {
	display: inline-block;
	transform: rotate(45deg);
	content: "";
	display: inline-block;
	background-color: $light-color;
	width: 50px;
	height: 50px;
	border-radius: 100% 8px;
	box-shadow: 1px 1px 15px $light-color, -1px -1px 15px $light-color;
}

.socket {
	display: inline-block;
	background-color: #035C2A;
	height: 15px;
	width: 15px;
	transform: translatey(-17px);
}
.remove {
	display: inline-block;
	transform: translatex(20px) translatey(-20px);
}

.save {
	// display: block;
}

.sp-palette {
max-width: 200px;
}


            
          
!
            
              var lightCount = 5;
// var strip = $("singleKeyframeContainer:last .strip");
var lightColor;

var spectrumOptions = {
	color: "rgb(244, 204, 204)",
	showPalette: true,
	showPaletteOnly: true,
	togglePaletteOnly: true,
	togglePaletteMoreText: 'more',
	togglePaletteLessText: 'less',
	localStorageKey: "bulbcolors",
	maxSelectionSize: 20,
	showInitial: true,
	allowEmpty: false,
	showInput: true,
	preferredFormat: "name",
	hideAfterPaletteSelect: true,
	change: function(color) {
		$(this).css({
			"background-color": color,
			"box-shadow": "1px 1px 15px " + color + ", -1px -1px 15px " + color
		});
	},
	palette: [
		["rgb(255, 0, 0)", "rgb(0, 255, 0)",
			"rgb(0, 0, 255)", "rgb(255, 255, 255)"
		]
	]
};

function Light() {
	return new $('<li>').append($("<div>", {
			"class": "socket"
		})).append($("<div>", {
			"class": "light"
		}).css({
			"background-color": "red",
			"box-shadow": "1px 1px 15px " + "red" + ", -1px -1px 15px " + "red"
		}).spectrum(spectrumOptions))
		.append($("<button>", {
				"class": "remove"
			}).text("X")
			.on("click", function() {
				$(this).parent().fadeOut(300, function() {
					$(this).remove();
				});
			}));
}

function addLightTo(myElement) {
	myElement.append(new Light);
	// console.log("Light added");
}

for (var i = 0; i < lightCount; i++) {
	addLightTo($(".singleKeyframeContainer:last .strip"));
}

function addEmptyKeyframe() {
	$(".emptyKeyframeContainer").clone(false, true).appendTo(".keyframesContainer").removeClass("hidden emptyKeyframeContainer");
}

function copyToNewKeyframe(myElement) {
	var newElement = myElement.clone(true, true);
	// var newElement = myElement.clone(false, true);
	newElement.find(".light").spectrum(spectrumOptions);
	newElement.find(".timeInput").val("");
	newElement.appendTo($(".keyframesContainer"));
}

function deleteKeyframe(myElement) {
	if (window.confirm("Do you really want to remove this Keyframe?")) {
		myElement.remove();
	}
}

function save() {
	var output = [];
	
	$(".singleKeyframeContainer:not(.hidden)").each(function(keyframeIndex, keyframeElement) {
		var time = Number($( this ).find(".timeInput").val());
		var transition = $( this ).find(".transition").val();
		var lights = [];
		$( this ).find(".light").each(function(lightIndex, lightElement) {
			var lightColor = $( this ).css('backgroundColor');
			lights.push(lightColor);
		});
		output.push({
			"keyframe": keyframeIndex,
			"time" : time,
			"transition" : transition,
			"lights" : lights
		});
	});
	// $(".light").each(function(index, value) {
	// 	output[index] = $(this).css('backgroundColor');
	// });
	console.log(JSON.stringify(output));

	// $.ajax({
	// 	type: "POST",
	// 	url: "http://raspberrypi.local:5000/todos",
	// 	data: "task=something new",
	// 	// success: console.log("Success"),
	// 	// dataType: dataType
	// });

	return;
}

// function clearSwatches() {
// 		window.localStorage.removeItem("bulbcolors");
// }
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console