cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <h1>An Accessible Carousel for CNIB</h1>
<div class="page-controls">
	<p id="screen-reader-test">Screen Reader Detection</p>
	<button id="show-labels">Show Labels</button>
</div>
<section id="content-before">
	<h2>Content before carousel</h2>
</section>
<section id="carousel" class="clearfix">
	<h2 class="carousel-heading screen-reader-only">A carousel</h2>
	<div class="carousel-controls">
		<fieldset aria-label="carousel buttons" class="carousel-buttons" aria-controls="carousel">
			<a href="#content-after" aria-label="skip carousel" id="skip" class="screen-reader-only">Skip carousel</a>
			<!-- 				<button value="pause" id="pause" aria-label="pause" class="carousel-button">||</button>   -->
			<button value="prev" aria-label="previous" id="prev" class="carousel-button"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/313305/speedicon.svg" alt="Speed Control" /></button>
			<button value="go" id="go" class="carousel-button"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/313305/pauseicon.svg" alt="Pause" /></button>
			<button value="next" id="next" aria-label="next" class="carousel-button"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/313305/replayicon.svg" alt="Replay" /></button>
		</fieldset>
	</div>
	<div class="carousel-nav">
		<h3 class="screen-reader-only">Carousel Navigation</h3>
		<div class="carousel-nav-thumbnail current-slide" id="nav-item-0">
			<a href="#item-0">
				<h4 class="carousel-nav-heading">Slide 1 Title</h4>
				<!-- 				<p class="carousel-nav-summary">Slide 1 summary</p> -->
				<img aria-hidden="true" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/313305/CNIB-bg1.png" class="carousel-nav-image" alt="" />
			</a>
		</div>
		<div class="carousel-nav-thumbnail" id="nav-item-1">
			<a href="#item-1">
				<h4 class="carousel-nav-heading">Slide 2 Title</h4>
				<!-- 				<p class="carousel-nav-summary">Slide 2 summary</p> -->
				<img aria-hidden="true" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/313305/CNIB-bg2.png" class="carousel-nav-image" alt="" />
			</a>
		</div>
		<div class="carousel-nav-thumbnail" id="nav-item-2">
			<a href="#item-2">
				<h4 class="carousel-nav-heading">Slide 3 Title</h4>
				<!-- 				<p class="carousel-nav-summary">Slide 3 summary</p> -->
				<img aria-hidden="true" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/313305/CNIB-bg3.png" class="carousel-nav-image" alt="" />
			</a>
		</div>
	</div>
	<div class="carousel-content clearfix" aria-live="polite">
		<h3 class="screen-reader-only">Carousel Content</h3>
		<div aria-hidden="true" class="carousel-item hidden" id="item-0">
			<h4 class="carousel-heading">Welcome</h4>
			<p class="carousel-description">This is a Carousel</p>
			<a href="#nav-item-1" class="screen-reader-only">Continue to next carousel navigation item</a>
			<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/313305/CNIB-bg1.png" class="carousel-image" alt="Description of slide 1 photo" />
		</div>
		<div aria-hidden="true" class="carousel-item hidden" id="item-1">
			<h4 class="carousel-heading">This is Slide 1</h4>
			<p class="carousel-description">This is some info about the slide. It goes into detail about the topic.</p>
			<a href="#nav-item-1" class="screen-reader-only">Continue to next carousel navigation item</a>
			<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/313305/CNIB-bg2.png" class="carousel-image" alt="Description of slide 2 photo" />
		</div>
		<div aria-hidden="true" class="carousel-item hidden" id="item-2">
			<h4 class="carousel-heading">This is Slide 2</h4>
			<p class="carousel-description">This is some info about the slide. It goes into detail about the topic.</p>
			<a href="#nav-item-1" class="screen-reader-only">Continue to next carousel navigation item</a>
			<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/313305/CNIB-bg3.png" class="carousel-image" alt="Description of slide 3 photo" />
		</div>
	</div>

</section>
<section id="content-after">
	<h2>Content after carousel</h2>
</section>
            
          
!
            
              li[aria-hidden='true'] {
	display: none;
}

li[aria-hidden='false'] {
	display: block;
}

section {
	clear: both;
}

.hidden {
	display: none;
}

.hidden-behind {
	z-index: -5;
	/* 	z-index: 10; */
}

.hidden-behind-off {
	z-index: 15;
	position: relative;
}

.screen-reader-only {
	clip: rect(1px, 1px, 1px, 1px);
	height: 1px;
	width: 1px;
	overflow: hidden;
	position: absolute !important;
}

.current-slide {
	border: 2px solid red;
}

#screen-reader-test {
	color: red;
}

@media speech {
	#screen-reader-test {
		color: green;
	}
}

#carousel {
	border: 3px solid black;
	position: relative;
	
	.carousel-controls {
		position: absolute;
		top: 0;
		left: 0;
		z-index: 10;
		
		.carousel-buttons {
			border: none;
			width: 100%;
			/* 	margin: 0 auto; */
		}
		
		.carousel-button {
			background-color: transparent;
			border: 0;
		}
		
		.carousel-button:focus,
		.carousel-button:hover {
			cursor: pointer;
			
			img {
				/* 	color: black; */
			}
		}
	}
	
	.carousel-nav {
		float: right;
		width: 25%;
		height: 400px;
		overflow-y: scroll;
		
		.carousel-nav-thumbnail {
			position: relative;
			height: calc(400px/3);
		}
		
		.carousel-nav-thumbnail a {
			text-decoration: none;
		}
		
		.carousel-nav-image {
			/* 	width: 100%; */
			height: 100%;
			position: absolute;
			top: 0;
			left: 0;
			z-index: -1;
		}
		
		.carousel-nav-heading {
			margin: 0;
			padding: 60px 0;
			text-align: center;
			text-decoration: none;
			color: white;
		}
	}
	
	.carousel-content {
		position: relative;
		height: 400px;
		background-color: #eeeeee;
		width: 75%;
		float: left;
		
		.carousel-item {
			background: transparent;
			/* 	position: relative; */
			height: 400px;
			//width: 100%;
			overflow: hidden;
			
			.carousel-heading {
				z-index: 10;
				position: relative;
				top: 20%;
				text-align: center;
				color: white;
				
			}
			
			.carousel-description {
				z-index: 10;
				position: relative;
				top: 20%;
				text-align: center;
				color: white;
			}
			
			a {
				padding-left: 3px;
				padding-right: 3px;
				border-radius: 3px;
				color: #000090;
			}
			
			a:focus,
			a:hover {
				color: white;
				background-color: #000090;
				text-decoration: none;
			}
			
			.carousel-image {
				/* 	float: right;
				width: 200px;
				margin-right: 1em;
				margin-left: 1em; */
				position: absolute;
				top: 0;
				left: 0;
				width: 100%;
				/* 	height: 100%; */
				/* 	height: 400px; */
				z-index: 0;
			}
		}
	}
}

//.main-heading {
//	padding-top: 1em;
//	margin-left: 1em;
//}

.carousel-controls {}

.clearfix:after {
	content: "";
	display: table;
	clear: both;
}
            
          
!
            
              $(document).ready(function() {

	$(".v-item").css("display", "none");
	$(".v-item:first-child").css("display", "block");

	$("button#show-labels").click(function() {
		if (($('#show-labels').html()) == "Hide Labels") {
			$('#show-labels').html("Show Labels");
			$('.screen-reader-only-off').addClass('screen-reader-only').removeClass('screen-reader-only-off');
			$('.hidden-behind-off').addClass('hidden-behind').removeClass('hidden-behind-off');
		} else {
			$('#show-labels').html("Hide Labels");
			$('.screen-reader-only').addClass('screen-reader-only-off').removeClass('screen-reader-only');
			$('.hidden-behind').addClass('hidden-behind-off').removeClass('hidden-behind');
		}
	});

	$(".skip-to-content").focus(function() {
		autoPlay = false;
		$("button#go img").attr("src", "https://s3-us-west-2.amazonaws.com/s.cdpn.io/313305/playicon.svg").attr("alt", "Play");
	});

	$(".carousel-item a").mouseover(function() {
		$("button#go img").attr("src", "https://s3-us-west-2.amazonaws.com/s.cdpn.io/313305/playicon.svg").attr("alt", "Play");
		autoPlay = false;
	});

	$(".carousel-item a").focus(function() {
		$("button#go img").attr("src", "https://s3-us-west-2.amazonaws.com/s.cdpn.io/313305/playicon.svg").attr("alt", "Play");
		autoPlay = false;
	});

	const TIME_BETWEEN_SLIDES_DEFAULT = 4000;
	const TIME_BETWEEN_SLIDES_SLOW = 10000;
	const FADE_IN_TIME = 500;
	const FADE_OUT_TIME = 500;
	const FAST_FADE_IN_TIME = 500;
	const FAST_FADE_OUT_TIME = 500;
	const TRANSITION_RUNNING_RETEST_PERIOD = 200;

	var slideIntervalTimer;
	var autoPlay = true;
	var currentslide = 0;
	var initSlide = 0;
	var pauseSlideshow = false;
	var transitionRunning = false;
	var numSlides = $('.carousel-item').length;
	var speed = TIME_BETWEEN_SLIDES_DEFAULT;
	var screenReaderDetection = false;

	if ($("#screen-reader-test").css('color') == 'green') {
		autoPlay = false;
		screenReaderDetection = true;
	}

	$(".carousel-item:eq(0)").attr("aria-hidden", "false").fadeIn(FADE_IN_TIME, function() {
		slideIntervalTimer = setInterval(function() {
			showCurrentSlide();
		}, speed);
	});

	function showCurrentSlide() {
		if (autoPlay && !pauseSlideshow) {
			transitionRunning = true;
			$(".carousel-item:eq(" + currentslide + ")").attr("aria-hidden", "true").fadeOut(FADE_OUT_TIME, function() {
				currentslide = (currentslide + 1) % numSlides;
				$(".current-slide").removeClass("current-slide");
				$("#nav-item-" + currentslide).addClass("current-slide");
				$(".carousel-item:eq(" + currentslide + ")").attr("aria-hidden", "false").fadeIn(FADE_IN_TIME, function() {
					transitionRunning = false;
				});
			});
		}
	}

	$("button#next").click(function() {
		pauseSlideshow = true;
		if (transitionRunning) {
			setTimer(function() {
				$("button#next").click();
			}, TRANSITION_RUNNING_RETEST_PERIOD);
		} else {
			transitionRunning = true;
			$(".carousel-item:eq(" + currentslide + ")").attr("aria-hidden", "true").fadeOut(FAST_FADE_OUT_TIME, function() {
				currentslide = 0;
				$(".carousel-item:eq(" + currentslide + ")").attr("aria-hidden", "false").fadeIn(FAST_FADE_IN_TIME, function() {
					transitionRunning = false;
					$("button#go img").attr("src", "https://s3-us-west-2.amazonaws.com/s.cdpn.io/313305/playicon.svg").attr("alt", "Play");
					$(".current-slide").removeClass("current-slide");
					$("#nav-item-" + currentslide).addClass("current-slide");
				});
			});
		}
		ev.preventDefault();
		return (false);
	});

	$("button#prev").click(function() {
		if (speed == TIME_BETWEEN_SLIDES_DEFAULT) {
			speed = TIME_BETWEEN_SLIDES_SLOW;
		} else {
			speed = TIME_BETWEEN_SLIDES_DEFAULT;
		}
		ev.preventDefault();
		return (false);
	});

	$("button#go").click(function() {

		if (!pauseSlideshow) {
			// Currently running, so pause autoPlay
			pauseSlideshow = true;
			$("button#go img").attr("src", "https://s3-us-west-2.amazonaws.com/s.cdpn.io/313305/playicon.svg");
			if (transitionRunning) {
				setTimer(function() {
					$("button#go").click();
				}, TRANSITION_RUNNING_RETEST_PERIOD);
			} else {
				transitionRunning = true;
				$(".carousel-item:eq(" + currentslide + ")").attr("aria-hidden", "true").fadeOut(FAST_FADE_OUT_TIME, function() {
					currentslide = (currentslide - 1) % numSlides;
					$(".carousel-item:eq(" + currentslide + ")").attr("aria-hidden", "false").fadeIn(FAST_FADE_IN_TIME, function() {
						transitionRunning = false;
					});
				});
			}
		} else {
			// Currently paused, start autoPlay
			$("button#go img").attr("src", "https://s3-us-west-2.amazonaws.com/s.cdpn.io/313305/pauseicon.svg").attr("alt", "Pause");
			if (transitionRunning) {
				setTimer(function() {
					$("button#go").click();
				}, TRANSITION_RUNNING_RETEST_PERIOD);
			} else {
				transitionRunning = true;
				$(".carousel-item:eq(" + currentslide + ")").attr("aria-hidden", "true").fadeOut(FADE_OUT_TIME, function() {
					currentslide = (currentslide + 1) % numSlides;
					$(".carousel-item:eq(" + currentslide + ")").attr("aria-hidden", "false").fadeIn(FADE_IN_TIME, function() {
						pauseSlideshow = false;
						transitionRunning = false;
						clearInterval(slideIntervalTimer);
						slideIntervalTimer = setInterval(function() {
							showCurrentSlide();
						}, speed);
						if (!screenReaderDetection) {
							autoPlay = true;
						}

					});
				});
			}
		}
		ev.preventDefault();
		return (false);
	});

	// add keyboard accessibility for all buttons, enter makes it click...
	$("button").keypress(function(ev) {
		if (ev.which == 13) {
			$(this).click();
			ev.preventDefault();
			return (false);
		}
	});

});
            
          
!
999px
Loading ..................

Console