61,115
社区成员
发帖
与我相关
我的任务
分享
.aHover
{
background-image:url(../Images/Power/Index/dw_03.jpg);
color:#187046;
}
.superiorMenu
{
width: 80px;
height:28px;
line-height: 28px;
float: left;
font-size: 13px;
border-right: 1px solid #5B7C6B;
text-align:center;
}
.superiorMenu a{ text-decoration:none; color:#ffffff; display:block; height:auto;}
.superiorMenu a:hover{background-image: url(../Images/Power/Index/dw_03.jpg);}
.sonMenu
{
width:140px;
line-height: 25px;
text-align:left;
position: absolute;
font-size: 13px;
border: 1px solid #6ABE9D;
background: white;
display: none;
}
$(".superiorMenu").hover(
function(e) {
$(this).addClass("aHover");
//获取该移动项下面的子菜单
var menu = $(this).children("div");
//子菜单与左端的距离
var width;
//菜单父div(id=z)与div(id=menu_div)的距离
var zWidth = $("#z").css("margin-left").substring(0, $("#z").css("margin-left").length - 2) * 1;
//菜单父div(id=menu_div)与浏览器左端的距离
var mWidth = $("#menu_div").offset().left;
//判断div(id=menu_div)与浏览器左端的距离,如果小于=0则子菜单位置为div(id=z)的宽度+跟菜单索引*跟菜单宽度
//否则为根菜单与浏览器左端的距离
if ($("#menu_div").offset().left <= 0) {
//width = $(this).index() * $(this).width();
width = $(this).offset().left;
} else {
width = $(this).offset().left;
}
menu.css({ left: width, "top": $("#logo_img_div").height() + $(this).height() });
menu.show();
},
function() {
//获取该移动项下面的子菜单
var menu = $(this).children("div");
menu.hide();
$(this).removeClass("aHover");
}
)
<!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>
<title></title>
<style type="text/css" >
#nav{ background-color:Gray;}
#nav a{ color:White;}
#nav a:hover,
#nav a.hover{color:Red;}
</style>
<script type="text/javascript" src="js/jquery-1.6.4.min.js" ></script>
</head>
<body>
<div id="nav">
<a href="#">home</a> <a href="#">product</a>
</div>
<script type="text/javascript" >
$("a").mouseover(function() {
$(this).addClass("hover");
});
</script>
</body>
</html>
.superiorMenu a:hover,
.superiorMenu a.aHover
{background-image: url(../Images/dw_03.jpg); color:#187046;}
{
background-image:url(../Images/dw_03.jpg);
color:#187046;
}