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

              
                <form id="slider" @submit.prevent>
	
	<!-- This label and input are the "real" elements. -->
	<label for="range" :style="{ color: getHappinessColor }">Happiness: {{ val }}%</label>
	<input v-model.number="val" id="range" type="range" min=0 max=100>

	<!-- This div and label is what makes the visual effect, but is hidden to assistive technologies -->
	<div class="slider outer">
		<label 
			for="range"
			:style="{ width: `${val}%`, borderRadius: greaterThanFifty, background: getSliderBackground }"
			class="slider inner"
			aria-hidden="true"
		>
		</label>
		<span class="emoji" :style="{ transform: `translateX(${getPlacement})` }">
			{{ getHappiness }}
		</span>
	</div>
</form>
              
            
!

CSS

              
                :root {
	--yellow: #ffd100;
	--orange: #ff6a13;
	--darkGray: #53565a;
	--midGray: #888b8d;
	--white: #fff;
	--roundness: 1.25em;
}

*, *:after, *:before {
	box-sizing: border-box;
	color: var(--darkGray);
}

body {
	font-family: Nunito, sans-serif;
	min-height: 100vh;
	width: 100vw;
	display: flex;
	place-items: center;
	margin: 0;
	background: var(--white);
	font-size: .5rem;
	
	@media (min-width: 440px) {
		font-size: .75rem;
	}
	
	@media (min-width: 600px) {
		font-size: 1rem;
	}
}

#slider {
	padding: 2rem 2rem 4remq; //Extra padding on bottom helps center-align slider
	display: grid; //TBH grid is probably a little overkill here but ¯\_(ツ)_/¯
	justify-content: stretch;
	width: 100%;
	max-width: 37.5em;
	margin: auto;
	
	input {
		grid-row: 2 / 3;
		grid-column: 1 / 2;
		width: 100%;
		position: relative;
		z-index: 1;
		opacity: 0;
		height: calc(var(--roundness) * 2);
		cursor: pointer;
		
		&:focus + .outer {
			box-shadow: 0 0 0 0.1em var(--white), 0 0 0 0.2em var(--orange);			

			& .emoji {	
				/* Alternate focus style on the emoji button */
				// box-shadow: 0 0 0 0.05em var(--orange);
				// background: var(--white);
			}
		}
	}

	& > label {
		width: 100%;
		margin: auto;
		font-size: 1.5em;
		padding: 0 0 0.5em;
	}

	.outer {
		grid-row: 2 / 3;
		grid-column: 1 / 2;
		width: 100%;
		border-radius: var(--roundness);
		margin: auto;
		height: calc(var(--roundness) - 0em);
		background: var(--midGray);
		display: flex;
		align-content: center;
		align-items: center;
		position: relative;
		z-index: 0;
	}

	label.inner {
		position: absolute;
		width: 100%;
		height: 100%;
		background: var(--white);
		border-top-left-radius: var(--roundness)!important;
		border-bottom-left-radius: var(--roundness)!important;
		position: absolute;
		transition: all .15s cubic-bezier(0.5, 0.4, .2, 1);
		transform-origin: left;
	}
		
	.emoji {
		margin-left: -.2em;
		display: inline-block;
		width: 1em;
		height: 1em;
		transition: all .15s cubic-bezier(0.5, 0.4, .2, 1);
		border-radius: var(--roundness);		
		text-align: right;
		font-size: calc(var(--roundness) * 2);
		line-height: 1.1;
	}
}
              
            
!

JS

              
                const slider = new Vue ({
	el: '#slider',
	
	data: () => ({
		val: 70
	}),
	
	// Just for fun, set the value randomly each time the component loads. (Means the value of 70 above really doesn't do anything.)
	mounted() {
		this.val = Math.floor(Math.random() * 101)
	},
	
	computed: {
		// This is not ideal just because it needs knowledge of how wide the track is.
		// Ideally I'd like to do this more dynamically so it works with any track length,
		// but for the sake of smooth animations I kept it like this.
		getPlacement() {
			return ((this.val * 14.5)) + `%`;
		},
		
		// This is kinda hacky, but if the background is rounded at too low a value, you can see it peeking out from behind the emoji.
		greaterThanFifty() {
			return this.val > 50 ? `var(--roundness)` : `0`;
		},
		
		// Makes the color smoothly move from red to orange to yellow
		getHappinessColor() {
  		return `rgba(255, ${106 + (103 / 100 * this.val)}, ${(Math.floor(this.val * -1 / 7.692)) + 13}`;
		},
		
		// Adjusts the amount of yellow in the filled slider
		getSliderBackground() {
			return `linear-gradient(to right, var(--orange), ${(this.val * -1) + 125}%, var(--yellow))`
		},
		
		// Changes which emoji is displayed
		getHappiness() {
			let moods = ["😡","😠","đŸ˜Ļ","☚ī¸","🙁","😐","🙂","😊","😄","😃","😍"]
			
			if (this.val === 0) {
				return "đŸ¤Ŧ";
			} 
				
			return moods[(Math.floor(this.val / 10))];
		}
	}
});
              
            
!
999px

Console