Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <!-- Add the class "over" so that the bar overlays the content -->

<div class="scroll-bar">
	<ol>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
	</ol>
</div>
              
            
!

CSS

              
                .scroll-bar {
	overflow: hidden;
}

.scroll-bar .outer {
	height: 100%;
	overflow: hidden;
	position: relative;
}

.scroll-bar .inner {
	position: relative;
	top: 0;
}

.scroll-bar.enabled .inner {
	width: calc(100% - 8px);
}

.scroll-bar.over .inner {
	width: 100% !important;
}

/* Track */
.scroll-bar .track {
	width: 8px;
	height: 100%;
	background: red;
	display: none;
	position: absolute;
	top: 0;
	right: 0;
	pointer-events: none;
}

.scroll-bar.enabled .track {
	display: block;
}

.scroll-bar.over .track {
	background: transparent;
}

/* Bar */
.scroll-bar .track figure {
	width: 8px;
	height: 80px;
	background: blue;
	position: relative;
	margin: 0;
}

/* Only for this demo */
body {
	margin: 0;
}

.scroll-bar {
	height: 100vh;
}

ol {
	margin: 0;
	padding: 0;
	list-style-position: inside;
}
/* Only for this demo */
              
            
!

JS

              
                var scroll_bar = document.querySelectorAll('.scroll-bar');

if(scroll_bar) {
	scroll_bar.forEach(function(element) {
		// Wrapper
		var content = element.innerHTML;

		var inner = document.createElement('div');
		inner.classList.add('inner');
		inner.innerHTML = content;
		
		var track = document.createElement('div');
		track.classList.add('track');
		var bar = document.createElement('figure');
		track.appendChild(bar);
		
		var outer = document.createElement('div');
		outer.classList.add('outer');
		outer.appendChild(inner);
		outer.appendChild(track);

		element.innerHTML = '';
		element.appendChild(outer);

		// Check if need scroll
		var outer_height = outer.offsetHeight;
		var inner_height = inner.offsetHeight;

		if (inner_height > outer_height) {
			element.classList.add('enabled');
		}

		// Avoid window scroll
		function preventDefault(event) {
			event.preventDefault();
		}
		
		// On wheel
		outer.onwheel = function(event) {
			outer_height = outer.offsetHeight;
			inner_height = inner.offsetHeight;

			// Check if still need scroll after inner height change
			if (inner_height > outer_height) {
				var wheel_delta_y = -event.deltaY;
				var position_top  = inner.offsetTop;
				var limit         = -(inner_height - outer_height);
				var scrolled      = position_top + wheel_delta_y;
				var bar_height    = bar.offsetHeight;
				var bar_limit     = outer_height - bar_height;
				var bar_scrolled  = bar_limit * scrolled / limit;

				window.addEventListener('wheel', preventDefault, {passive: false});

				if (wheel_delta_y >= 1 && position_top >= 0) {
					inner.style.top = 0;
					bar.style.top = 0;
				}

				else if (wheel_delta_y <= -1 && position_top <= limit) {
					inner.style.top = limit + 'px';
					bar.style.top = bar_limit + 'px';
				}

				else {
					inner.style.top = scrolled + 'px';
					bar.style.top = bar_scrolled + 'px';
				}
			}
		}

		outer.onmouseleave = function() {
			window.removeEventListener('wheel', preventDefault, {passive: false});
		}

		// On touch
		outer.ontouchstart = function(touchstart) {
			var touch_start = touchstart.touches[0].clientY;

			outer.ontouchmove = function(touchmove) {
				var touch_end = touchmove.touches[0].clientY;

				outer_height = outer.offsetHeight;
				inner_height = inner.offsetHeight;

				// Check if still need scroll after inner height change
				if (inner_height > outer_height) {
					var wheel_delta_y = (touch_start - touch_end) * -1;
					var position_top  = inner.offsetTop;
					var limit         = -(inner_height - outer_height);
					var scrolled      = position_top + wheel_delta_y;
					var bar_height    = bar.offsetHeight;
					var bar_limit     = outer_height - bar_height;
					var bar_scrolled  = bar_limit * scrolled / limit;

					window.addEventListener('touchmove', preventDefault, {passive: false});

					if (wheel_delta_y >= 1 && position_top >= 0) {
						inner.style.top = 0;
						bar.style.top = 0;
					}

					else if (wheel_delta_y <= -1 && position_top <= limit) {
						inner.style.top = limit + 'px';
						bar.style.top = bar_limit + 'px';
					}

					else {
						inner.style.top = scrolled + 'px';
						bar.style.top = bar_scrolled + 'px';
					}
				}
			}
		}

		outer.ontouchend = function() {
			window.removeEventListener('touchmove', preventDefault, {passive: false});
		}

		// Check if inner height changed
		var observer = new MutationObserver(function() {
			var new_inner_height = inner.offsetHeight;

			if (new_inner_height != inner_height) {
				inner.style.top = 0;
				bar.style.top = 0;

				if (new_inner_height <= outer_height) {
					element.classList.remove('enabled');
				}

				else {
					element.classList.add('enabled');
				}
			}
		});

		observer.observe(inner, {
			attributes: true,
			characterData: true,
			childList: false,
			subtree: true
		});

		window.onresize = function() {
			outer_height = outer.offsetHeight;
			inner_height = inner.offsetHeight;

			inner.style.top = 0;
			bar.style.top = 0;

			if (inner_height <= outer_height) {
				element.classList.remove('enabled');
			}

			else {
				element.classList.add('enabled');
			}
		}
	});
}
              
            
!
999px

Console