Reputation: 95
I am trying to put a delay effect on my submenu.
<ul id="main-menu">
<li class="firstLevel hasSubmenu"><a href="/inmotus/" class="firstLevel">
<nav class="submenu">
<ul>
<li><a href="#"><font><font class="">About</font></font></a></li>
<li><a href="#"><font><font class="">Sample</font></font></a></li>
<li><a href="#"><font><font>Inmotus misse & Vision</font></font></a></li>
<li><a href="#"><font><font class="">Voluptatem</font></font></a></li>
<li><a href="#"><font><font class="">Ratione</font></font></a></li>
</ul>
</nav>
<ul>
Problem: How can i apply a delay on my .submenu class every time .hasSubmenu class is hovered?
Please help me...
Upvotes: 0
Views: 564
Reputation: 136
$(document).ready(function(){
$('.submenu').hide();
$( '.hasSubmenu' ).hover( function() {
_this = $(this).parents().find('.submenu');
setTimeout(function() {
_this.fadeIn(); }, 500);
}, function() {
_this.fadeOut();
});
});
Try something like this. (FIXED)
http://jsfiddle.net/swp64ydv/1/
Upvotes: 0
Reputation: 2581
i am not sure what you expect after delay but assuming you want it to appear
$('.hasSubmenu').mouseenter(function()
{
setTimeout(function(){handleMouseAction(true);},500)
}).mouseleave(function()
{
setTimeout(function(){handleMouseAction(false);},500)
});
function handleMouseAction(actionFLag)
{
if(actionFlag)
{
$('submenu').show();
}
else
{
$('submenu').hide();
}
}
Upvotes: 0
Reputation: 7122
You code is not properly as i understand from your code, below is a solution. I hope it will help you.
$(document).ready(function(){
$('ul li.firstLevel').click(function(){
$('ul ul').slideToggle();
});
})
Change the value
$('ul ul').slideToggle(600);
then you manage the delay timing.
Upvotes: 1
Reputation: 9508
If your code is based on javascript, This link would be much helpful. http://cherne.net/brian/resources/jquery.hoverIntent.html
hoverIntent is a plug-in that attempts to determine the user's intent... like a crystal ball, only with mouse movement! It is similar to jQuery's hover method. However, instead of calling the handlerIn function immediately, hoverIntent waits until the user's mouse slows down enough before making the call.
It has a configuration to change the delay on hover, have a look at is it suit to you.
Upvotes: 1