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 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 class="temp">
	<div class="temp__logo">Nest</div>
	<div class="temp__comet"></div>
	<canvas class="temp__fizz"></canvas>
	<div class="temp__label">Temp</div>
	<div class="temp__value">0</div>
	<div class="temp__dial"></div>
</div>
              
            
!

CSS

              
                * {
	border: 0;
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}
:root {
	--bg: #fff;
	font-size: calc(16px + (24 - 16) * (100vw - 320px) / (1280 - 320));
}
body {
	background: var(--bg);
	display: grid;
	place-items: center;
	font: 1em/1.5 sans-serif;
	height: 100vh;
	overflow: hidden;
}
.temp {
	--angle: 0;
	--hue: 240;
	background-image:
		radial-gradient(
			100% 100% at 50% 50%,
			hsl(var(--hue),90%,17%) 3.55em,
			hsla(var(--hue),90%,17%,0) 3.6em
		),
		radial-gradient(
			100% 100% at 50% 50%,
			hsl(var(--hue),90%,10%),
			hsl(var(--hue),90%,23%) 4.65em,
			hsl(var(--hue),90%,55%) 4.85em 4.9em,
			#17181c 5.1em 6.85em,
			#17181c00 6.9em
		),
		radial-gradient(100% 100% at 50% 0,#f1f2f4,#8f95a3);
	border-radius: 50%;
	box-shadow: 0 -0.25em 1.5em 0.5em #0004;
	display: flex;
	flex-direction: column;
	line-height: 1;
	position: relative;
	padding: 1em;
	text-align: center;
	width: 15em;
	height: 15em;
}
.temp:after, .temp__dial, .temp__comet, .temp__fizz {
	position: absolute;
}
.temp:after, .temp__comet, .temp__dial {
	border-radius: inherit;
}
.temp:after, .temp__dial {
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
}
.temp:after {
	background: 
		radial-gradient(100% 100% at 67% 17%,#fff3,#fff0 6em);
	content: "";
	display: block;
	z-index: 2;
}
.temp__logo {
	font-family: "Baloo Paaji 2", sans-serif;
	color: #abafba;
	letter-spacing: -0.1em;
	margin-bottom: 3.75em;
	text-transform: lowercase;
	transform: scaleY(1.1);
}
.temp__comet {
	background:
		radial-gradient(
			100% 100% at 50% 50%,
			hsl(var(--hue),90%,10%),
			hsl(var(--hue),90%,20%) 3.25em,
			hsl(var(--hue),90%,17%) 3.3em 3.35em,
			hsla(var(--hue),90%,17%,0) 3.4em
		),
		conic-gradient(#fff0,#fff calc(1deg * var(--angle)),#fff0 calc(1deg * var(--angle)));
	top: calc(50% - 3.5em);
	left: calc(50% - 3.5em);
	width: 7em;
	height: 7em;
}
.temp__fizz {
	display: block;
	top: calc(50% - 3.3em);
	left: calc(50% - 3.3em);
	width: 6.6em;
	height: 6.6em;
}
.temp__label, .temp__value {
	color: #fff;
	font-family: "Unica One", monospace;
	position: relative;
	z-index: 1;
}
.temp__label {
	font-size: 0.6em;
	letter-spacing: 0.5em;
	text-transform: uppercase;
	transform: translateX(0.25em) scaleY(0.9);
}
.temp__value {
	font-size: 3.5em;
}
.temp__dial {
	cursor: grab;
	z-index: 3;
}
.temp__dial:active {
	cursor: grabbing;
}
/* Dark theme */
@media (prefers-color-scheme: dark) {
	:root {
		--bg: #2e3138;
	}
}
              
            
!

JS

              
                document.addEventListener("DOMContentLoaded",function(){
	const thermostat = new Thermostat(".temp");
});

class Thermostat {
	constructor(el) {
		this.el = document.querySelector(el);
		this.temp = 0;
		this.tempMin = 0;
		this.tempMax = 100;
		this.fizz = null;
		this.fizzParticleCount = 600;
		this.fizzParticles = [];
		this.fc = null;
		this.fW = 240;
		this.fH = 240;
		this.fS = window.devicePixelRatio;
		this.init();
	}
	init() {
		window.addEventListener("keydown",this.kbdEvent.bind(this));

		if (this.el) {
			this.fizz = this.el.querySelector(".temp__fizz");
			if (this.fizz) {
				this.fc = this.fizz.getContext("2d");

				let f = this.fizzParticleCount;

				while (f--) {
					this.fizzParticles.push(
						{
							radius: 1, 
							// from center to comet ring
							minDist: this.randInt(100,115),
							maxDist: this.randInt(85,115),
							// rotation along the comet ring circumference
							minRot: this.randInt(-180,180),
							maxRot: this.randInt(-180,180),
							// position
							x: 0, 
							y: 0
						}
					);
				}

				this.fizz.width = this.fW * this.fS;
				this.fizz.height = this.fH * this.fS;
				this.fc.scale(this.fS,this.fS);
			}
		}

		Draggable.create(".temp__dial",{
			type: "rotation",
			bounds: {
				minRotation: 0, 
				maxRotation: 359
			},
			onDrag: () => {
				this.tempAdjust("drag");
			}
		});
	}
	degToRad(deg) {
		return deg * (Math.PI / 180);
	}
	randInt(min,max) {
		return Math.round(Math.random() * (max - min)) + min;
	}
	angleFromMatrix(transVal) {
		let matrixVal = transVal.split('(')[1].split(')')[0].split(','),
			[cos1,sin] = matrixVal.slice(0,2),
			angle = Math.round(Math.atan2(sin,cos1) * (180 / Math.PI)) * -1;
		
		// convert negative angles to positive
		if (angle < 0)
			angle += 360;
		
		if (angle > 0)
			angle = 360 - angle;
		
		return angle;
	}
	kbdEvent(e) {
		let kc = e.keyCode;

		if (kc) {
			// up or right
			if (kc == 38 || kc == 39)
				this.tempAdjust("u");
			// left or down
			else if (kc == 37 || kc == 40)
				this.tempAdjust("d");
		}
	}
	tempAdjust(inputVal) {
		/*
		inputVal can be the temp as an integer, "u" for up, 
		"d" for down, or "drag" for dragged value
		*/
		if (this.el) {
			let cs = window.getComputedStyle(this.el),
				tempDisplay = this.el.querySelector(".temp__value"),
				tempDial = this.el.querySelector(".temp__dial"),
				tempRange = this.tempMax - this.tempMin,
				hueStart = 240,
				hueEnd = 360,
				hueRange = hueEnd - hueStart,
				notDragged = inputVal != "drag";
			// input is an integer
			if (!isNaN(inputVal)) {
				this.temp = inputVal;
			// input is a given direction
			} else if (inputVal == "u") {
				if (this.temp < this.tempMax)
					++this.temp;

			} else if (inputVal == "d") {
				if (this.temp > this.tempMin)
					--this.temp;
			// GreenSock drag was used
			} else if (inputVal ==  "drag") {
				if (tempDial) {
					let tempDialCS = window.getComputedStyle(tempDial),
						trans = tempDialCS.getPropertyValue("transform"),		
						angle = this.angleFromMatrix(trans);

					this.temp = (angle / 360) * tempRange + this.tempMin;
				}
			}
			// keep the temperature within bounds
			if (this.temp < this.tempMin)
				this.temp = this.tempMin;
			else if (this.temp > this.tempMax)
				this.temp = this.tempMax;
			// use whole number temperatures for keyboard control
			if (notDragged)
				this.temp = Math.round(this.temp);

			let relTemp = this.temp - this.tempMin,
				frac = relTemp / tempRange,
				angle = frac * 360,
				newHue = hueStart + (frac * hueRange);

			// fizz
			let c = this.fc;
			if (c) {
				c.clearRect(0,0,this.fW,this.fH);
				c.fillStyle = `hsla(${newHue},100%,50%,0.5)`;
				c.globalAlpha = 0.25 + (0.75 * frac);

				let centerX = this.fW / 2,
					centerY = this.fH / 2,
					fizzCount = this.fizzParticles.length;

				this.fizzParticles.forEach((p,i) => {
					let pd = p.minDist + frac * (p.maxDist - p.minDist),
						pa = p.minRot + frac * (p.maxRot - p.minRot);

					p.x = centerX + pd * Math.sin(this.degToRad(pa));
					p.y = centerY + pd * Math.cos(this.degToRad(pa));

					c.beginPath();
					c.arc(p.x,p.y,p.radius,0,Math.PI * 2);
					c.fill();
					c.closePath();
				});
			}
			// CSS variables
			this.el.style.setProperty("--angle",angle);
			this.el.style.setProperty("--hue",newHue);
			// hidden dial
			if (tempDial && notDragged)
				tempDial.style.transform = `rotate(${angle}deg)`;
			// display value
			if (tempDisplay)
				tempDisplay.textContent = Math.round(this.temp);
		}
	}
}
              
            
!
999px

Console