as4s1n
New Member
- Messages
- 174
- Reaction score
- 4
- Points
- 0
I am making a hover-offset menu and I got it mostly working. However, when you hover over the roots (links for each menu) the menu pops up, but unforutnately, the same place which is fine for root1, but when you get to root3 you can't get to the menu. I think the coordinates I get are of the parent element of the roots and displays it in the same place for all of them. Please help.
HTML:
Javascript:
Here is a link to a live site.
Also, a side note: I noticed that Google Chrome 5 doesn't like the li display:inline; as it always displays as a block list. Is there any fix for that?
HTML:
HTML:
<!-- ... -->
<ol>
<li>
<a href="javascript:void(0)">Root 1</a>
<ol>
<li>
<a href="javascript:void(0)">Root 1 Child 1</a>
<a href="javascript:void(0)">Root 1 Child 2</a>
</li>
</ol>
</li>
<li>
<a href="javascript:void(0)">Root 2</a>
<ol>
<li>
<a href="javascript:void(0)">Root 2 Child 1</a>
<a href="javascript:void(0)">Root 2 Child 2</a>
</li>
</ol>
</li>
<li>
<a href="javascript:void(0)">Root 3</a>
<ol>
<li>
<a href="javascript:void(0)">Root 3 Child 1</a>
<a href="javascript:void(0)">Root 3 Child 2</a>
</li>
</ol>
</li>
</ol>
Code:
$(document).ready(function() {
$("#hoverEvent li").find("ol").css({'display' : 'none', 'position' : 'absolute', 'width' : '100px'});
$("#hoverEvent li").hover(
function() {
mouseCoords;
$(this).find("ol").css({'display' : 'block'});
$(this).find("ol").offset({'top' : posy, 'left' : posx});
},
function() {
$(this).find("ol").css({'display' : 'none'});
});
});
// Get the coordinates of the mouse
function mouseCoords(e) {
var
posy =0,
posx =0;
if(!e) {var e = window.event;}
if(e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;
}
else if(e.clientX || e.clientY) {
posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
}
else {
document.getElementById("help").innerHTML = "You cannot run this";
}
return posx,posy;
}
Also, a side note: I noticed that Google Chrome 5 doesn't like the li display:inline; as it always displays as a block list. Is there any fix for that?
Last edited: