<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.HoverPopUp
{
background-color: yellow;
width: 80px;
border: 1px solid black;
position: absolute;
left: 0px;
top: 0px;
}
</style>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
var left = 10;
var top = 10;
var IsMouseOverPopUp;
$(document).ready(function () {
BindHoverMenu();
});
function BindHoverMenu() {
$(".HoverMenu").css("display", "none");
$(".HoverTarget").mouseover(function () {
IsMouseOverPopUp = false;
var p = GetCordinates($(this).get(0));
$("#dvHover").css("left", $(this).get(0).offsetWidth + left + "px");
$("#dvHover").css("top", p.y + top + "px");
$("#dvHover").css("display", "block");
$("#dvHover").html($(this).parent().children(".HoverMenu").html());
$(this).mouseout(function () {
HideHoverMenu();
});
});
$("#dvHover, .HoverTarget").mouseover(function () {
IsMouseOverPopUp = true;
});
$("#dvHover, .HoverTarget").mouseout(function () {
IsMouseOverPopUp = false;
HideHoverMenu();
});
}
function GetCordinates(obj) {
var p = {};
p.x = obj.offsetLeft;
p.y = obj.offsetTop;
while (obj.offsetParent) {
p.x = p.x + obj.offsetParent.offsetLeft;
p.y = p.y + obj.offsetParent.offsetTop;
if (obj == document.getElementsByTagName("body")[0]) {
break;
}
else {
obj = obj.offsetParent;
}
}
return p;
}
function HideHoverMenu() {
setTimeout(function () {
if (!IsMouseOverPopUp) {
$("#dvHover").css("display", "none");
}
}, 500);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<a href="javascript:;" class="HoverTarget">Menu1</a>
<div class="HoverMenu">
<table>
<tr>
<td>
<a href="javascript:;">SubMenu1</a>
</td>
</tr>
<tr>
<td>
<a href="javascript:;">SubMenu2</a>
</td>
</tr>
<tr>
<td>
<a href="javascript:;">SubMenu3</a>
</td>
</tr>
</table>
</div>
</div>
<div>
<a href="javascript:;" class="HoverTarget">Menu2</a>
<div class="HoverMenu">
<table>
<tr>
<td>
<a href="javascript:;">SubMenu1</a>
</td>
</tr>
<tr>
<td>
<a href="javascript:;">SubMenu2</a>
</td>
</tr>
<tr>
<td>
<a href="javascript:;">SubMenu3</a>
</td>
</tr>
<tr>
<td>
<a href="javascript:;">SubMenu4</a>
</td>
</tr>
</table>
</div>
</div>
<div id="dvHover" class="HoverPopUp" style = "display:none">
</div>
</form>
</body>
</html>