js實現(xiàn)的動畫導(dǎo)航菜單效果代碼
本文實例講述了js實現(xiàn)的動畫導(dǎo)航菜單效果代碼。分享給大家供大家參考。具體如下:
這是一款簡單的動畫導(dǎo)航菜單效果,每個菜單項的下邊有一個橫線會隨著鼠標(biāo)的對應(yīng)而自動滑動,指明當(dāng)前菜單的位置。
運(yùn)行效果截圖如下:

在線演示地址如下:
http://demo.jb51.net/js/2015/js-animate-nav-menu-style-codes/
<!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>動畫導(dǎo)航菜單</title>
<style type="text/css">
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote{margin:0; padding:0;}
body { font:12px "\5B8B\4F53",san-serif; color:#808080; padding-top:6px; }
a { text-decoration:none; color:#808080 }
a:hover { text-decoration:underline; color:#ba2636 }
ul, li { list-style:none; }
#nav{ padding:41px 0 0 0; height:27px;width:542px; overflow:hidden; float:right; margin-right:17px;position:relative ;}
#nav ul{ height:27px; width:100%; background: url(i/naVbotBdr.gif) repeat-x 0 100%; }
#nav ul li{ width:67px; height:24px; float:left; padding-right:28px; display:inline; cursor:pointer; overflow:hidden}
#nav a{background:#999;width:100%; height:24px; display:block; float:left; outline:none; color:#fff; line-height:24px; text-align:center; font-size:16px; font-weight:bold; overflow:hidden}
#navCur{ position:absolute; left:0; bottom:0; height:3px; color:#F00; width:67px; margin:0; padding:0; display: block; float:none; background:#FF0000; cursor:pointer; overflow:hidden}
</style>
</head>
<body>
<div id="nav">
<ul class="cf">
<li><a href="" hidefocus="true">1</a></li>
<li><a href="1" hidefocus="true">2</a></li>
<li class="cur"><a href="2" hidefocus="true">3</a></li>
<li><a href="3" hidefocus="true">4</a></li>
<li><a href="4" hidefocus="true">5</a></li>
<li><a href="5" hidefocus="true">6</a></li>
</ul>
<span id="navCur"></span>
</div>
<script type="text/javascript">
(function(){
var curPostion,thisLeft, curPostion_1;
var obj = getId('nav').getElementsByTagName('ul')[0], timer = null ,navCur = getId('navCur'),x,liArr = getId('nav').getElementsByTagName('li'),liLength = liArr.length-1;
for (var x=0;x<liArr.length; x++ ){
liArr[liLength].style.paddingRight = "0";
var li = liArr[x],curPostion = navCur.offsetLeft;
if(li.className == "cur"){
navCur.style.left = li.offsetLeft + "px";
}
li.onmouseover=function(){
clearTimeout(timer);
thisLeft = this.offsetLeft;
if (thisLeft > navCur.offsetLeft)
{
hover();
}
else
{
curPostion_1 = this.offsetLeft;
out();
}
};
li.onmouseout=function(){
clearTimeout(timer);
if (curPostion < navCur.offsetLeft)
{
curPostion_1 = curPostion;
out();
}
else
{
thisLeft = curPostion;
hover();
}
};
}
function hover(){
if (navCur.offsetLeft <= thisLeft)
{
var a = Math.max(parseInt((thisLeft - navCur.offsetLeft) / 15), 3);
navCur.style.left = navCur.offsetLeft + a + "px";
timer = setTimeout(arguments.callee, 5);
}
else
{
navCur.style.left = thisLeft + "px";
clearTimeout(timer);
}
}
function out(){
if (navCur.offsetLeft >= curPostion_1)
{
var a = Math.max(parseInt((navCur.offsetLeft - curPostion_1) / 15), 3);
navCur.style.left = navCur.offsetLeft - a + "px";
timer = setTimeout(arguments.callee, 5);
}
else
{
navCur.style.left = curPostion_1 + "px";
clearTimeout(timer);
}
}
function getId(id){
return document.getElementById(id)
}
})();
</script>
</body>
</html>
希望本文所述對大家的JavaScript程序設(shè)計有所幫助。
- 在iframe里的頁面編寫js,實現(xiàn)在父窗口上創(chuàng)建動畫效果展開和收縮的div(不變動iframe父窗口代碼)
- js實現(xiàn)div拖動動畫運(yùn)行軌跡效果代碼分享
- js+css實現(xiàn)文字散開重組動畫特效代碼分享
- js實現(xiàn)按鈕顏色漸變動畫效果
- 使用ngView配合AngularJS應(yīng)用實現(xiàn)動畫效果的方法
- JS實用的動畫彈出層效果實例
- JS簡單實現(xiàn)動畫彈出層效果
- js運(yùn)動動畫的八個知識點(diǎn)
- js實現(xiàn)動畫特效的文字鏈接鼠標(biāo)懸停提示的方法
- JS實現(xiàn)網(wǎng)頁右側(cè)帶動畫效果的伸縮窗口代碼
相關(guān)文章
Bootstrap modal 多彈窗之疊加顯示不出彈窗問題的解決方案
Bootstrap modal 多彈窗之疊加顯示不出彈窗問題,今天小編抽時間給大家分享下解決方案,需要的朋友參考下2017-02-02
JavaScript常見函數(shù)類型和用途實現(xiàn)場景分析
在JavaScript中,除了惰性函數(shù)和防抖函數(shù)外,還有許多其他有用的函數(shù)模式和功能函數(shù),以下是一些常見的函數(shù)類型和用途,感興趣的朋友一起看看吧2024-12-12
JS實現(xiàn)黑色風(fēng)格的網(wǎng)頁TAB選項卡效果代碼
這篇文章主要介紹了JS實現(xiàn)黑色風(fēng)格的網(wǎng)頁TAB選項卡效果代碼,通過簡單的頁面元素遍歷控制頁面tab切換效果,具有一定參考借鑒價值,需要的朋友可以參考下2015-10-10
用JavaScript動態(tài)建立或增加CSS樣式表的實現(xiàn)方法
下面小編就為大家?guī)硪黄肑avaScript動態(tài)建立或增加CSS樣式表的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-05-05
前端發(fā)布緩存導(dǎo)致白屏幾種解決方案總結(jié)
這篇文章主要介紹了前端發(fā)布緩存導(dǎo)致白屏的幾種解決方案,文章還介紹了Jenkins發(fā)布流程優(yōu)化和使用版本號方案,以減少發(fā)布緩存問題,每種方案都有其優(yōu)缺點(diǎn),需要根據(jù)實際情況進(jìn)行選擇和調(diào)整,需要的朋友可以參考下2025-04-04

