Created
May 22, 2013 21:03
-
-
Save petehalverson/5630894 to your computer and use it in GitHub Desktop.
JS for touch subnav. Requires: Modernizr (expects the touch class) and hover classes in CSS.
For Bootstrap:
if ($('html').hasClass('touch'))
{
$('html').click(function(e) {
$('.navbar-nav > li').removeClass('hover');
});
$('.navbar-nav > li').click(function(e) {
if (!$(this).hasClass('hover') && $(this).has('ul.dropdown-menu').length > 0)
{
e.preventDefault();
e.stopPropagation();
}
$('.navbar-nav > li').removeClass('hover');
$(this).toggleClass('hover');
});
}
Load Fastclick (https://github.com/ftlabs/fastclick) for this script to work in iOS8.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternatively, using Bootstrap's dropdown menus, you may want to disable to the forced click on Desktops when using
data-toggle="dropdown"
.Still using Modernizr: