Pen Settings

HTML

CSS

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

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

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.

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

              
                  <h1> ARIA Carousel</h1>
	<div class="carousel" id="carousel">
		<div class="carousel-items">
			<div id="focuspoint" class="visually-hidden" tabindex="-1"></div>
			<div aria-hidden="false" class="carousel-item">
			<div class="carousel-content">
			<h2 class="carousel-heading">This is a carousel</h2>	
			<p>Carousels are bad, we don't recommend using them.</p></div>
				
			</div>     
				<div aria-hidden="true" class="carousel-item hidden">              
				<div class="carousel-content">
				<h2 class="carousel-heading">If you have to use a carousel</h2>	
				<p>Use ours, it's special. Unlike other carousels, we've made this one accessible</p>  
				<button class="carousel-button">Button 2</button></div>
			</div>  

			<div aria-hidden="true" class="carousel-item hidden">              
				<div class="carousel-content">
				<h2 class="carousel-heading">But Seriously....</h2>
				<p>Don't use a carousel! They're bad</p>   
				<button class="carousel-button">Button 3</button></div>
			</div>  
		</div>
	</div>
<div class="carousel-buttons">
<!--<button value="pause" id="pause" aria-label="pause" class="carousel-button">||</button>-->
	<button value="go" id="go" class="carousel-button">Pause</button>
	<button value="prev" aria-label="previous" id="prev" class="carousel-button"><</button>
	<button value="next" id="next" aria-label="next" class="carousel-button">></button>
</div>
              
            
!

CSS

              
                body{
	font-family: 'Open Sans', sans-serif;
}
.visually-hidden { /*https://developer.yahoo.com/blogs/ydn/clip-hidden-content-better-accessibility-53456.html*/
    position: absolute !important;
    clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
    clip: rect(1px, 1px, 1px, 1px);
    padding:0 !important;
    border:0 !important;
    height: 1px !important;
    width: 1px !important;
    overflow: hidden;
}
body:hover .visually-hidden a, body:hover .visually-hidden input, body:hover .visually-hidden button { display: none !important; }

.carousel-buttons{
width:auto;
vertical-align:bottom;
border:none;}

.carousel {
margin: 10px 0;
width: 600px; 
height: 450px; 
border: 2px solid black;
}
div.carousel-item {

}

div.carousel-item[aria-hidden='true'] {
   display: none;
}
div.carousel-item[aria-hidden='false'] {
   display:block ;   
}

.hidden {display:none;}

.carousel-item
{
	width:600px;
	height:400px;
}

.carousel-item
{
	background-color: #000000;
}
.carousel-content
{
	font-size:1em;
	text-align:center;
	background-color:#000;
	color:#fff;
}
.carousel-content h2
{
	font-size: 2.5em;
	font-weight:800;
}
.carousel-content p
{
font-size: 1.5em;
}
              
            
!

JS

              
                
$(document).ready(function(){
	var timer;//will be interval timer
	var transition_time = 1000; // 1 second
	var time_between_slides = 4000; // 4 seconds
	var counter = 1; //use to set slide ids
	var numslides = $("div.carousel-items div.carousel-item").length; //count the number of slides
	var current = $("div.carousel-item[aria-hidden='false']");	
	$('#focuspoint').text("Showing Slide "+counter+" of "+numslides);
	autoPlay = "on";
	
	//Add ids to all carousel items
	$("div.carousel-items div.carousel-item").each(function (){
		$(this).attr("id","slide"+counter);
		$(this).attr("data-slidenumber",counter);
		counter++;
		});

	$(window).on('load', function(){
		console.log("Page loaded - AutoPlay Value is: "+autoPlay);
		if(autoPlay == "on"){
			if(!timer){
				timer=setInterval(function(){shownext(numslides);},time_between_slides); // every 4 secs next slide
			}
		}
	});

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

  $("button#next").click(function(){
		$('#focuspoint').focus();
		shownext(numslides);
  });
  
    $("button#prev").click(function(){
		$('#focuspoint').focus();
		showprevious(numslides);
  });
  

$("#pause").click(function(ev){
	timer= window.clearInterval(timer);
	autoPlay = "off";
	console.log("Pause button pressed - AutoPlay Value is: "+autoPlay);
	return (false);
});

$('#carousel, .carousel-items div.carousel-item').hover(function(ev) {
	console.log("Hover in - AutoPlay Value is: "+autoPlay);
	timer=window.clearInterval(timer);
	 
	return (false);
},
function(){
	console.log("Hover out - AutoPlay Value is:"+autoPlay);
	if(autoPlay == "on"){
		var hasfocus  = $("#carousel").children().has(":focus").length
		console.log("Focused Kid: "+hasfocus);
		if(!timer && !hasfocus){
		timer=window.setInterval(function(){shownext(numslides);},time_between_slides);
		}
	}
	return (false);
});

$('#carousel').focusin(function(ev) {
	console.log("Focus in - AutoPlay Value is:"+autoPlay);
	timer=window.clearInterval(timer);
	
	return (false);
});

$('#carousel').focusout(function(ev) {
	console.log("Focus out - AutoPlay Value is:"+autoPlay);
	if(autoPlay == "on"){
		if(!timer){
		timer=window.setInterval(function(){shownext(numslides);},time_between_slides);
		}
	}
	return (false);
});

$("button#go").click(function(){
	
	console.log("Play Button pressed, turning autoplay on - AutoPlay Value is:"+autoPlay);
	if(autoPlay == "on"){
		timer= window.clearInterval(timer);
		autoPlay = "off";
		$("#go").text("Play");
	}
	else if(autoPlay == "off"){
		if(!timer){
		timer=window.setInterval(function(){shownext(numslides);},time_between_slides);
		autoPlay = "on";
		$("#go").text("Pause");
		}
	}	
});    


});

//Function to show the next slide
function shownext(numslides){
	var current = $("div.carousel-item[aria-hidden='false']");	
	var next = current.next("div");
	if(next.length)
	{
		current = next;
		$(current).attr("aria-hidden","false");
		$(current).removeClass("hidden");
		$(current).siblings("div.carousel-item").attr("aria-hidden","true");
		$(current).siblings("div.carousel-item").addClass("hidden");
	}
	else
	{
		current = $("div.carousel-items div.carousel-item:first");
		$(current).attr("aria-hidden","false");
		$(current).removeClass("hidden");
		$(current).siblings("div.carousel-item").attr("aria-hidden","true");
		$(current).siblings("div.carousel-item").addClass("hidden");
	}
	$('#focuspoint').text("Showing Slide "+current.attr('data-slidenumber')+" of "+numslides);
}

//Function to show the previous slide
function showprevious(numslides){
	var current = $("div.carousel-item[aria-hidden='false']");	
	var previous = current.prev("div.carousel-item");
	if(previous.length)
	{
		current = previous;
		$(current).attr("aria-hidden","false");
		$(current).removeClass("hidden");
		$(current).siblings("div.carousel-item").attr("aria-hidden","true");
		$(current).siblings("div.carousel-item").addClass("hidden");
	}
	else
	{
		current = $("div.carousel-items div.carousel-item:last");
		$(current).attr("aria-hidden","false");
		$(current).removeClass("hidden");
		$(current).siblings("div.carousel-item").attr("aria-hidden","true");
		$(current).siblings("div.carousel-item").addClass("hidden");
	}
	$('#focuspoint').text("Showing Slide "+current.attr('data-slidenumber')+" of "+numslides);
	
}


              
            
!
999px

Console