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.

            
              <div id="wrapper">
	<div id="blurb">
		<h2>World's Most Unintuitive Volume Slider</h2>
		<p>When gravity meets volume slider. You want to turn the volume up, but gravity tells you otherwise and slides back down again. Try it!</p><p>TURN UP YOUR SOUND!<br />If no music playing, please refresh!</p>
	</div>
  	<div id="slider" class="slider-vertical">
		<div class="knob" style="top: 358px"></div>
  	</div>
</div>
<audio src="https://www.bensound.com/bensound-music/bensound-jazzcomedy.mp3" autoplay loop></audio>
            
          
!
            
              html, body{
  width: 100%;
  height: 100%;
  background: rgb(223,30,30);
  background: linear-gradient(90deg, rgba(223,30,30,1) 0%, rgba(226,83,21,1) 100%);
  overflow: hidden;
}
#wrapper{
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  -wekbit-transform: translate(-50%, -50%);
}
#blurb{
	position: absolute;
	left: -350px;
	width: 300px;
	text-align: right;
	color: #FFB372;
	line-height: 24px;
}
#blurb h2{
	line-height: 30px;
	color: #FFDD77;
}
#slider{
  position: relative;
  width: 40px;
  height: 400px;
  border-radius: 20px;
  background: rgb(193,7,7);
  background: linear-gradient(90deg, rgba(193,7,7,1) 0%, rgba(241,109,52,1) 100%);
}
#slider:before{
	content: '100% \A 50% \A 0%';
	position: relative;
	top: -70px;
	left: 60px;
	color: #FFB372;
	font-size: 1.5rem;
	line-height: 180px;
	white-space: pre;
}
#slider:after{
  content: '';
  position: absolute;
  z-index: 0;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 370px;
  transform: translate(-50%, -50%);
  -wekbit-transform: translate(-50%, -50%);
  border-radius: 5px;
  background: rgb(50,23,19);
  background: linear-gradient(180deg, rgba(50,23,19,1) 0%, rgba(36,16,8,1) 55%, rgba(20,6,0,1) 100%);
}
#slider .knob{
  position: absolute;
  z-index: 1;
  top: 378px;
  margin: 4px 3px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  border-radius: 17px;
  background: rgb(223,210,208);
  background: linear-gradient(135deg, rgba(223,210,208,1) 0%, rgba(230,212,205,1) 55%, rgba(48,27,18,1) 100%);
  box-shadow: 10px 10px 15px rgba(0, 0, 0, .8);
}
#slider .knob:before{
	content: '';
	position: absolute;
	top: 8px;
	left: -29px;
	width: 0;
	height: 0;
	border-top: 8px solid transparent;
	border-left: 8px solid rgba(0, 0, 0, 0.5);
	border-bottom: 8px solid transparent;
	opacity: 1;
	transition: opacity 1s ease;
}
#slider .knob:after{
	content: 'Slide me up';
	position: absolute;
	top: 0;
	left: -130px;
	padding: 8px;
	color: white;
	text-align: right;
	border-radius: 5px;
	background-color: rgba(0, 0, 0, 0.5);
	opacity: 1;
	transition: opacity 1s ease;
}
#slider .knob.active:before,
#slider .knob.active:after{
	opacity: 0;
}
            
          
!
            
              $(document).ready(() => {

	$('audio')[0].volume = 0;
  
	/* Vertical Slider */
	$('#slider.slider-vertical .knob').draggable({axis: 'y', containment: '#slider', scroll: false}).mousedown(function() {
		$(this).addClass('active');
	});
	setInterval(function() {
		var value = Math.abs(parseInt($('#slider.slider-vertical .knob').css('top'))/358 - 1);
		if (value > 0.01) $('audio')[0].volume = value;
		else $('audio')[0].volume = 0;
	}, 25);
	
	$('body').mouseup(function() {
		$('#slider.slider-vertical .knob').animate({top: 358}, 500, 'easeOutBounce');
	});

});
            
          
!
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.

Console