<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery鼠标经过背景跟随滑动的导航菜单 - 代码家园</title>
<script language="JavaScript" src="js/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(e) {
//$("#mainbox").hide();
var navLi = $("#nav-div ul li"),
navUl = $("#nav-div ul"),
speed = 200;
function OnClick(){
n = navUl.find("li.on").index();
navUl.stop().animate({backgroundPosition:navLi.width()*n},speed);
}
OnClick();
navLi.hover(
function(){
n = $(this).index();
navUl.stop().animate({backgroundPosition:navLi.width()*n},speed);
},
function(){
OnClick();
})
navLi.click(function(){
$(this).addClass("on").siblings().removeClass("on")
});
$(window).scroll(function() {
if($(window).scrollTop() > $("#nav").height()+50){
$("#nav").addClass("scoll_nav")
}
else{
$("#nav").removeClass( "scoll_nav")
}
});
})
</script>
<script type="text/javascript">
//
window.tabHanlerId = null;
function setTab(name,cursel,n){
//
_clearTabHanler();
//
for(i=1;i<=n;i++){
var menu=document.getElementById(name+i);
var con=document.getElementById("con_"+name+"_"+i);
menu.className=i==cursel?"hover":"";
con.style.display=i==cursel?"block":"none";
}
};
// 鼠标移入conTwoTabs时
function conTwoTabsMouseover(){
//
_clearTabHanler();
// 判断ID,然后设置上方hover 的样式
};
// 清除
function _clearTabHanler(){
if(window.tabHanlerId){
window.clearTimeout(window.tabHanlerId);
window.tabHanlerId = null;
}
};
// 延迟隐藏Tab
function hideTab(){
//
_clearTabHanler();
window.tabHanlerId = window.setTimeout(_hideTab, 70);
//
function _hideTab(){
//
var name = 'two';
var n = 4;
//
for(i=1;i<=n;i++){
var menu=document.getElementById(name+i);
var con=document.getElementById("con_"+name+"_"+i);
menu.className="";
con.style.display="none";
}
};
};
</script>
<style type="text/css">
body, html {
padding: 0;
margin: 0;
}
a {
text-decoration: none;
color: #FFF;
font-weight: bold;
font-size: 14px;
}
div, ul, li {
padding: 0;
margin: 0;
}
ul {
list-style: none;
}
/*选项卡2*/
#Tab2 {
width: 576px;
margin: 0px;
padding: 0px;
margin: 0 auto;
}
.con_two_tabs {
height : 100px;
}
/*菜单class*/
.Menubox {
width: 100%;
background: url(bg2.gif);
height: 28px;
line-height: 28px;
}
.Menubox ul {
margin: 0px;
padding: 0px;
}
.Menubox li {
float: left;
display: block;
cursor: pointer;
width: 114px;
text-align: center;
color: #949694;
font-weight: bold;
}
.Menubox li.hover {
padding: 0px;
background: #fff;
width: 116px;
border-left: 1px solid #A8C29F;
border-top: 1px solid #A8C29F;
border-right: 1px solid #A8C29F;
background: url(bg1.gif);
color: #739242;
font-weight: bold;
height: 27px;
line-height: 27px;
}
.Contentbox {
clear: both;
margin-top: 0px;
border: 1px solid #A8C29F;
border-top: none;
height: 181px;
text-align: center;
padding-top: 0px;
}
#nav-div {
width: 1020px;
height: 42px;
background: #1BA2E1;
margin: auto;
position: relative;
}
ul {
width: 100%;
height: 42px;
list-style: none;
cursor: pointer;
background: url(images/nav_on.png) no-repeat;
}
#nav-div ul li {
width: 100px;
height: 42px;
line-height: 42px;
text-align: center;
margin: auto;
float: left;
color: #FFF;
cursor: pointer;
}
#nav-div ul li:hover a {
color: #FF6;
}
#liItemPaner {
width: 100px;
height: 40px;
background: #FC0;
position: absolute;
}
.nav-side {
width: 1020px;
margin: auto;
height: 42px;
background: #1BA2E1;
}
.scoll_nav {
width: 100%;
position: fixed;
top: 10px;
z-index: 10000;
}
#nav .nav-on {
color: #F00;
}
</style>
</head>
<body>
<br>
<br>
<br>
<div class="top"></div>
<div id="nav" class="nav-side">
<div id="nav-div">
<ul>
<li class="on"><a href="#" target="_blank">门户首页</a></li>
<li id="two1" onmouseout="hideTab()" onmouseover="setTab('two',1,4)"><a href="https://www.baidu.com/" target="_blank">口岸资讯</a></li>
<li id="two2" onmouseout="hideTab()" onmouseover="setTab('two',2,4)"><a href="https://www.baidu.com/" target="_blank">政务中心</a></li>
<li id="two3" onmouseout="hideTab()" onmouseover="setTab('two',3,4)"><a href="https://www.baidu.com/" target="_blank">用户服务</a></li>
<li id="two4" onmouseout="hideTab()" onmouseover="setTab('two',4,4)"><a href="https://www.baidu.com/" target="_blank">口岸协会</a></li>
<li><a href="https://www.baidu.com/" target="_blank">综合查询</a></li>
<li><a href="https://www.baidu.com/" target="_blank">招商引资</a></li>
<li><a href="https://www.baidu.com/" target="_blank">通关服务</a></li>
</ul>
</div>
<div id="mainbox" class="Contentbox">
<div id="con_two_1" class="con_two_tabs" onmouseout="hideTab()" onmouseover="conTwoTabsMouseover()" style="display:none">鼠标指向变换鼠标指向变换同一页面只需更改ID可以重复使用鼠标指向变换同一页面只需更改ID可以重复使用1</div>
<div id="con_two_2" class="con_two_tabs" onmouseout="hideTab()" onmouseover="conTwoTabsMouseover()" style="display:none">鼠标指向变换鼠标指向变换同一页面只需更改ID可以重复使用鼠标指向变换同一页面只需更改ID可以重复使用2</div>
<div id="con_two_3" class="con_two_tabs" onmouseout="hideTab()" onmouseover="conTwoTabsMouseover()" style="display:none">鼠标指向变换鼠标指向变换同一页面只需更改ID可以重复使用鼠标指向变换同一页面只需更改ID可以重复使用3</div>
<div id="con_two_4" class="con_two_tabs" onmouseout="hideTab()" onmouseover="conTwoTabsMouseover()" style="display:none">鼠标指向变换鼠标指向变换同一页面只需更改ID可以重复使用鼠标指向变换同一页面只需更改ID可以重复使用4</div>
</div>
</div>
0000000
</body>
</html>
评论0