labs-scnm
6/13/2013 - 11:33 AM

Scrolling shadows by @kizmarh and @leaverou

Scrolling shadows by @kizmarh and @leaverou

{"view":"split-vertical","fontsize":"100","seethrough":"","prefixfree":"1","page":"css"}
<h1>CSS-only shadow-scrolling effect.</h1>
<h2>With hover-scroll</h2>
<div class="scrollbox">
	<ul>
		<li>Ah! Scroll below!</li>
		<li>2</li>
		<li>3</li>
		<li>4</li>
		<li>5</li>
		<li>6</li>
		<li>7</li>
		<li>8</li>
		<li>9</li>
		<li>10</li>
		<li>1</li>
		<li>2</li>
		<li>3</li>
		<li>4</li>
		<li>5</li>
		<li>6</li>
		<li>7</li>
		<li>8</li>
		<li>9</li>
		<li>10</li>
		<li>1</li>
		<li>2</li>
		<li>3</li>
		<li>4</li>
		<li>5</li>
		<li>6</li>
		<li>7</li>
		<li>8</li>
		<li>The end!</li>
		<li>No shadow there.</li>
	</ul>
</div>
/**
 * Scrolling shadows by @kizmarh and @leaverou
 * Only works in browsers supporting background-attachment: local; & CSS gradients
 * Degrades gracefully
 */

html {
	background: white;
	font: 120% sans-serif;
}

.scrollbox {
	overflow-y: scroll;
	width: 200px;
	max-height: 200px;
	margin: 50px auto;

	background:
		/* Shadow covers */
		linear-gradient(white 30%, rgba(255,255,255,0)),
		linear-gradient(rgba(255,255,255,0), white 70%),
		
		/* Shadows */
		radial-gradient(50% 0, farthest-side, rgba(0,0,0,.2), rgba(0,0,0,0)),
		radial-gradient(50% 100%,farthest-side, rgba(0,0,0,.2), rgba(0,0,0,0));
	background-repeat: no-repeat;
	background-color: white;
	background-position:  top, bottom, top, bottom;
	background-size: 100% 40px, 100% 40px, 100% 14px, 100% 14px;
	
	/* Opera doesn't support this in the shorthand */
	background-attachment: local, local, scroll, scroll;
}

.scrollbox ul {
	transition: margin 1s;
	background-attachment:scroll;
}

.scrollbox ul:hover {
	margin-top: -510px;
}