Skip to content

Instantly share code, notes, and snippets.

@nielk
Created February 27, 2014 10:56
Show Gist options
  • Save nielk/9248074 to your computer and use it in GitHub Desktop.
Save nielk/9248074 to your computer and use it in GitHub Desktop.
menu accordéon accessible
/* click event & slide */
/* http://alex-d.fr/blog/ordre-des-evenements-javascript-click-touch-focus-et-confreres */
var click = false;
$('#menu li a').click( function() {
click = true;
var openMe = $(this).next();
var mySiblings = $(this).parent().siblings().find('ul');
if (openMe.is(':visible')) {
openMe.slideUp('normal');
} else {
mySiblings.slideUp('normal');
openMe.slideDown('normal');
}
setTimeout(function() {
click = false;
}, 150);
});
$('#menu li a').focus( function() {
setTimeout(function() {
if(!click) {
var openMe = $(this).next();
var mySiblings = $(this).parent().siblings().find('ul');
if (openMe.is(':visible')) {
openMe.slideUp('normal');
} else {
mySiblings.slideUp('normal');
openMe.slideDown('normal');
}
}
click = false;
}, 100);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment