Last active
September 28, 2016 12:21
-
-
Save advitum/7b56f60ebc14a632ae4e8b0ed3523414 to your computer and use it in GitHub Desktop.
You know how it is sometimes very hard to use a multi-level website navigation because it immediately closes when you accidentally move your mouse out of the navigation element and you have to start over? This script just adds a "lingering" class to the element, so your navigation can wait half a second before closing again.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$element.on('mouseenter', function(event) { | |
window.clearTimeout($(this).data('hover-timeout')); | |
$(this).addClass('hover').siblings('.hover').removeClass('hover'); | |
}).on('mouseleave', function(event) { | |
(function($element) { | |
$element.data('hover-timeout', window.setTimeout(function() { | |
$element.removeClass('hover'); | |
}, 500)); | |
})($(this)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment