<h1>Horizontal Sliding Navigation</h1>
<p>Resize the width of this window to see the horizontal sliding in action. Scroll to the left or right, and use the arrows as well. It should respond nicely to any situation.</p>

<nav class="slide-nav">
	<div class="slide-nav__wrapper slide-nav__wrapper--slid-start slide-nav__wrapper--full-right">
		<a class="slide-nav__wrapper__left-button">
			<span class="lumen-icon">
					<span class="lumen-icon__graphic lumen-icon__graphic--left-open" aria-hidden="true"><i class="arr-left"></i></span>
		</a>
		<ul class="slide-nav__list list--stripped" style="left: 8px;">
			<li class="slide-nav__list__item" id="id1">
				<a href="#id1 ">
Rogue Shadow
							<span class="slide-nav__count ">2</span>
						</a>
			</li>
			<li class="slide-nav__list__item" id="id2">
				<a href="#id2">
							Millenium Falcon
							<span class="slide-nav__count">1</span>
						</a>
			</li>
			<li class="slide-nav__list__item" id=" id3 ">
				<a href="#id3 ">
Tie Fighter
							<span class="slide-nav__count "></span>
						</a>
			</li>
			<li class="slide-nav__list__item" id="id4">
				<a href="#id4">
Death Star
							<span class="slide-nav__count">2</span>
						</a>
			</li>
			<li class="slide-nav__list__item active" id=" id5 ">
				<a href="id5 ">
							All
							<span class="slide-nav__count ">5</span>
						</a>
			</li>
		</ul>
		<a class="slide-nav__wrapper__right-button ">
			<span class="lumen-icon ">
					<span class="lumen-icon__graphic lumen-icon__graphic--right-open" aria-hidden="true "><i class="arr-right"></i></span>
			</span>
		</a>
	</div>
</nav>
$highlight: crimson;
* {
	font-family: Open Sans, Helvetica Neue, Helvetica, sans-serif;
	color: #777;
	scroll-behavior: smooth; // this has very limited browser support
}

h1 {
	color: $highlight;
	text-align: center;
}

p {
	width: 80%;
	margin: 0 auto;
	text-align: center;
}

[class^=arr-] {
	// create CSS arrows using rotated boxes with borders
	border: solid currentColor;
	border-width: 0 .1em .1em 0;
	display: inline-block;
	padding: .15em;
	margin-bottom: .2em;
	&:hover {
		border-color: $highlight;
	}
}

.arr-right {
	transform: rotate(-45deg);
	-webkit-transform: rotate(-45deg);
}

.arr-left {
	transform: rotate(135deg);
	-webkit-transform: rotate(135deg);
}

@import url(https://fonts.googleapis.com/css?family=Open+Sans);
.slide-nav {
	width: 80%;
	border-top: 1px solid #ccc;
	border-bottom: 1px solid #ccc;
	margin: 40px auto;
	position: relative;
	&::-webkit-scrollbar {
		display: none;
	}
	&__wrapper {
		position: relative;
		transition: width 1s ease-in-out;
		height: 48px; // fixed height to help with hiding the horizontal scrollbar
		overflow: hidden; // hides horizontal scrollbar
		&__left-button,
		&__right-button {
			background-color: white;
			z-index: 500;
			position: absolute;
			transition: opacity 0.5s ease;
			height: 100%;
			width: 76px;
			font-size: 24px;
			margin-top: 4px;
			.lumen-icon {
				cursor: pointer;
			}
			.lumen-icon__graphic {
				line-height: 1.75em;
				padding: 0 0.45em;
				color: #666;
			}
		}
		&__left-button {
			opacity: 0;
			left: 0;
			background: linear-gradient(to right, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 1) 45%, rgba(255, 255, 255, 0) 100%);
			margin-left: -1px;
			z-index: 0;
			pointer-events: none; // allows you to click through to layer underneath
			.lumen-icon__graphic {
				border-right: 1px solid #ccc;
			}
		}
		&__right-button {
			opacity: 1;
			right: 0;
			top: 0;
			text-align: right;
			background: linear-gradient(to right, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 55%, rgba(255, 255, 255, 1) 100%);
			margin-right: -1px;
			pointer-events: auto;
			.lumen-icon__graphic {
				border-left: 1px solid #ccc;
				&:hover {
					color: $highlight;
				}
			}
		}
		&--slid-start .slide-nav__wrapper__left-button {
			opacity: 1;
			z-index: 500;
			pointer-events: auto;
		}
		&--full-right .slide-nav__wrapper__right-button {
			opacity: 0;
			z-index: 0;
			pointer-events: none; // allows you to click through to layer underneath
		}
	}
	&__list {
		display: flex;
		white-space: nowrap;
		padding: 0 10px 20px; // bottom padding for hiding the scrollbar
		margin: 0;
		overflow-x: scroll;
		-ms-overflow-style: -ms-autohiding-scrollbar;
		box-sizing: content-box;
		height: 100%;
		list-style-type: none;
		@media(min-width: 640px) {
			justify-content: center;
		}
		&__item[class] {
			flex: 0 0 auto; // required for iOS Safari to display links at full width
			font-size: 16px;
			font-weight: 400;
			padding: 13px 0 10px;
			margin: 0 16px;
			border-bottom: 4px solid transparent;
			z-index: 1;
			&.active {
				border-bottom: 4px solid $highlight;
			}
			&:last-of-type {
				padding-right: 4px;
			}
			a {
				color: #666;
				text-decoration: none;
				&:hover {
					text-decoration: none;
					color: $highlight;
				}
			}
		}
	}
	&__count {
		font-size: 12px;
		color: white;
		background: #ccc;
		padding: 0 4px;
		border-radius: 2px;
		margin-left: 4px;
		line-height: 1em;
		&:empty {
			display: none;
		}
	}
}
View Compiled
function debounce(func, wait, immediate) {
	var timeout;
	return function() {
		var context = this,
			args = arguments;
		var later = function() {
			timeout = null;
			if (!immediate) func.apply(context, args);
		};
		if (immediate && !timeout) func.apply(context, args);
		clearTimeout(timeout);
		timeout = setTimeout(later, wait);
	};
}

// handle the side-sliding-nav!
let listWrapper = document.querySelector('.slide-nav__wrapper'),
	list = document.querySelector('.slide-nav__list'),
	leftButton = document.querySelector('.slide-nav__wrapper__left-button'),
	rightButton = document.querySelector('.slide-nav__wrapper__right-button'),
	clickScroll = function(button, amount) { // scroll when left or right buttons are clicked
		button.addEventListener('click', function() {
			list.scrollLeft += amount;
		})
	};
let hScrollWatcher = function() {
	let linksWidth = list.scrollWidth,
		listContainerWidth = listWrapper.scrollWidth,
		listMaxScroll = (listContainerWidth - linksWidth) * -1,
		buffer = 25, // pixels to buffer to accommodate for left/right margins
		listMaxScrollBuffer = (listMaxScroll - buffer),
		linksLeft = (list.scrollLeft);
	if (linksLeft > buffer) {
		listWrapper.classList.add('slide-nav__wrapper--slid-start');
	}
	if (linksLeft < buffer) {
		listWrapper.classList.remove('slide-nav__wrapper--slid-start');
	}
	if (linksLeft > listMaxScrollBuffer) {
		listWrapper.classList.add('slide-nav__wrapper--full-right');
	}
	if (listMaxScroll - linksLeft > buffer) {
		listWrapper.classList.remove('slide-nav__wrapper--full-right');
	}
};
hScrollWatcher(); // invoke this on page load
list.addEventListener('scroll', hScrollWatcher); // run this as scrolling takes place within the slide-nav

window.onresize = debounce(function() {
	hScrollWatcher(); // run this on debounce after resize
	listWrapper = document.querySelector('.slide-nav__wrapper'); // grab new width of component
}, 500);

clickScroll(leftButton, listWrapper.scrollWidth * -.5); // left button: scroll back 50% the width of the nav
clickScroll(rightButton, listWrapper.scrollWidth * .5); // right button: scroll forward 50% the width of the nav

// if a link is active, get its position and scroll to it
let activeSection = list.querySelector('.slide-nav__list__item:not(:first-of-type).active'), // define the active section, but not if it's the first one (because that causes issues with scrolling too far to the left).
	activePosition = activeSection.getBoundingClientRect().left; // get its left point
if (activeSection) { // if there's an active section...
	list.scrollLeft = activePosition - 80; // scroll to 80px past its left point (to clear the arrow)
}
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.