Skip to content

Instantly share code, notes, and snippets.

@wesleytodd
Last active December 11, 2015 15:59
Show Gist options
  • Save wesleytodd/4624680 to your computer and use it in GitHub Desktop.
Save wesleytodd/4624680 to your computer and use it in GitHub Desktop.
A quick delayed hover menu example
<html>
<head>
<style>
nav li ul {
display: none;
}
nav li.hover ul {
display: block;
}
</style>
<script>
jQuery(document).ready(function($){
$('nav li').each(function(){
var to, to2, $this = $(this);
$this.hover(function(){
clearTimeout(to);
to2 = setTimeout(function(){
$this.addClass('hover');
}, 300);
}, function(){
clearTimeout(to2);
to = setTimeout(function(){
$this.removeClass('hover');
}, 300);
});
});
});
</script>
</head>
<body>
<nav>
<ul>
<li>Item 1
<ul>
<li>Sub 1</li>
<li>Sub 2</li>
<li>Sub 3</li>
</ul>
</li>
<li>Items 2</li>
<li>Item 3</li>
</ul>
</nav>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment