Jquery Ul Li Hover Effect
Solution 1:
Common problem. The space between the parent menu item and .submenu
is the culprit.
An easy fix for this is wrapping .submenu
in a div
that's wide enough to act as bridge between the menu item and submenu.
See here -http://jsfiddle.net/BuJav/15/
CSS changes-
.submenu-wrapper {
position: absolute;
min-width: 160px;
min-height: 36px;
top: -4px;
left: 160px;
}
.submenu {
position: relative;
min-width: 160px;
min-height: 36px;
top: 0;
left: 10px;
background: url('../images/gradient_menuarea.png') repeat-x;
}
JS Changes -
$(function(){
$('#menu > li, .submenu > li').hover(
function(){
var submenu = $(this).find('ul.submenu');
if (submenu.hasClass('submenu')){
submenu.removeClass('hide');
}
},
function(){
var submenu = $(this).find('ul.submenu');
if (submenu.hasClass('submenu')){
submenu.addClass('hide');
}
});
});
Just so the submenu ul is targeted correctly.
Please note you can eliminate the JS by using this css
.submenu {display:none;}
#menu-areaulli:hover.submenu {display:block}
You won't need .hide
class on submenu ul either
Solution 2:
I don't know if it is considered acceptable in your current project, but you can do a quick-fix:
menu-area ullia{
width: 100%;
color: #F2F2F2;
display: block;
padding-right:10%;
}
You can change the value to whatever % you want that fixes your needs. Just do it enough to make sure the meets up with the sub-menu area. I didn't bother checking the exact value. Let me know if it works!
Solution 3:
try this: http://jsfiddle.net/UFevL/6/
HTML
<divid="menu"><ul><liclass="active"><ahref="?l=EL&m=932K59EciV">Menu #1</a></li><li><ahref="?l=EL&m=M-z-3crmAP">Menu #2</a></li><li><ahref="?l=EL&m=jpHiTwH1bT">Menu #3</a></li><li><ahref="?l=EL&m=Jwr0SIWoWX">Menu #4</a></li><li><ahref="?l=EL&m=QY8SgMl5JH">Menu #4</a></li><li><ahref="?l=EL&m=8GaCmPByu3">Menu #5</a></li><li><ul><li><ahref="?l=EL&m=ueHp2vYKUa">Submenu #1</a></li><li><ahref="?l=EL&m=HQvyKxum8q">Submenu #2</a></li><li><ahref="?l=EL&m=81cDaTOCsL">Submenu #3</a></li></ul><ahref="?l=EL&m=BQMppfQ0Dl">Menu #6</a></li><li><ahref="?l=EL&m=D3wTd4F5Mn">Menu #7</a></li></ul></div>
CSS
#menuul {
width: 160px;
padding: 4px;
margin: 0;
border: 2px solid #94AA13;
background-color: #fff;
border-radius: 4px;
}
#menuli {
position: relative;
padding: 0;
margin: 0;
}
#menuli + li {
margin-top: 4px;
}
#menua {
display: block;
padding: 020px;
font-size: 14px;
line-height: 36px;
color: #f2f2f2;
background-color: #283720;
border-radius: 4px;
}
#menuli > ul {
display: none;
position: absolute;
top: 0;
left: 100%;
margin: -4px0010px;
}
#menuli:hover > ul {
display: block;
}
#menuli:hover > ul:before {
display: block;
content: "";
position: absolute;
top: 0;
left: -10px;
width: 10px;
height: 100%;
}
JS... NONE!
The trick is in the :before element: http://caniuse.com/#search=before
If you can't use it, try adding a dummy div.
Post a Comment for "Jquery Ul Li Hover Effect"