javascript實現(xiàn)超炫的向上滑行菜單實例
更新時間:2015年08月03日 10:38:08 作者:jinfuiou
這篇文章主要介紹了javascript實現(xiàn)超炫的向上滑行菜單實現(xiàn)方法,以一個完整實例形式分析了javascript針對頁面元素的遍歷與樣式操作相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了javascript實現(xiàn)超炫的向上滑行菜單。分享給大家供大家參考。具體如下:
<!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>JS實現(xiàn)文字上下滑動導航</title>
<style type="text/css">
body { margin:0; background:#66FF99; }
ul { padding-left:0; margin:0; }
li { list-style:none; }
#nav { height:40px; background:#900; margin-top:50px; }
#nav ul { width:240px; height:40px; margin:0 auto; }
#nav li {height:40px; width:240px;}
#nav a { float:left; width:240px;position:relative; height:40px; overflow:hidden; font-size:14px; color:#e0e03a; text-decoration:none; cursor:pointer; }
#nav strong { float:left;width:240px; }
#nav span { float:left;width:200px; padding:0 20px; height:40px; line-height:40px; background:#900; clear:both; white-space:nowrap;}
#nav .active,#nav .current span { background:#600; color:#fff; }
#nav .current .active { color:#e0e03a; }
</style>
<script>
window.onload=function()
{
var oDiv=document.getElementById('nav');
var aStrong=oDiv.getElementsByTagName('strong');
var aA=oDiv.getElementsByTagName('a');
var iTarget=oDiv.getElementsByTagName('li')[0].offsetHeight;
for(var i=0; i<aStrong.length; i++)
{
aA[i].style.width=aStrong[i].style.width=aStrong[i].getElementsByTagName('span')[0].offsetWidth+'px';
aStrong[i].style.position='absolute';
aStrong[i].style.top=aStrong[i].style.left=0;
aStrong[i].onmouseover=function()
{
startMove(this, -iTarget);
};
aStrong[i].onmouseout=function()
{
startMove(this, 0);
};
}
};
function startMove(obj,target)
{
clearInterval(obj.iTime);
obj.iTime=setInterval(function(){
if(obj.offsetTop==target)
{
clearInterval(obj.iTime);
}
else
{
var iSpeed=(target-obj.offsetTop)/4;
iSpeed=iSpeed>0?Math.ceil(iSpeed):Math.floor(iSpeed);
obj.style.top=obj.offsetTop+iSpeed+'px';
}
}, 30);
}
</script>
</head>
<body>
<div id="nav">
<ul>
<li class="current">
<a href="#">
<strong>
<span>首頁</span>
<span class="active">首頁</span>
</strong>
</a>
</li>
<li>
<a href="#">
<strong>
<span>前端開發(fā)課程</span>
<span class="active">前端開發(fā)課程</span>
</strong>
</a>
</li>
<li>
<a href="#">
<strong>
<span>妙味視頻教程</span>
<span class="active">妙味視頻教程</span>
</strong>
</a>
</li>
<li>
<a href="#">
<strong>
<span>周末班上課安排</span>
<span class="active">周末班上課安排</span>
</strong>
</a>
</li>
<li>
<a href="#">
<strong>
<span>結課標準</span>
<span class="active">結課標準</span>
</strong>
</a>
</li>
<li>
<a href="#">
<strong>
<span>聯(lián)系妙味</span>
<span class="active">聯(lián)系妙味</span>
</strong>
</a>
</li>
</ul>
</div>
</body>
</html>
希望本文所述對大家的javascript程序設計有所幫助。
您可能感興趣的文章:
- JavaScript+CSS實現(xiàn)仿天貓側邊網(wǎng)頁菜單效果
- CSS javascript 結合實現(xiàn)懸浮固定菜單效果
- Javascript仿新浪游戲頻道鼠標懸停顯示子菜單效果
- javascript實現(xiàn)在下拉列表中顯示多級樹形菜單的方法
- Javascript實現(xiàn)鼠標右鍵特色菜單
- javascript簡單實現(xiàn)滑動菜單效果的方法
- javascript實現(xiàn)樹形菜單的方法
- javascript實現(xiàn)控制的多級下拉菜單
- JavaScript實現(xiàn)級聯(lián)菜單的方法
- JavaScript實現(xiàn)向右伸出的多級網(wǎng)頁菜單效果
相關文章
package.json中browser?module?main字段優(yōu)先級對比
這篇文章主要介紹了package.json中browser?module?main字段的優(yōu)先級詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-07-07
徒手實現(xiàn)關于JavaScript的24+數(shù)組方法
數(shù)組是我們?nèi)粘9ぷ髦杏玫淖铑l繁的一類數(shù)據(jù)結構,能幫助我們解決許多問題,而其本身也包含接近33個之多的方法,做了一個腦圖分類如下,熟練使用數(shù)組的你,是否想知道他們內(nèi)部的實現(xiàn)原理呢?接下來小編就帶大家進入主題,希望能幫助到你2021-09-09
Dom-api MutationObserver使用方法詳解
這篇文章主要為大家介紹了Dom-api MutationObserver使用方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-11-11
JS版的date函數(shù)(和PHP的date函數(shù)一樣)
這篇文章主要介紹了JS版的date函數(shù),使用方法和PHP的date函數(shù)一樣,需要的朋友可以參考下2014-05-05
微信小程序 教程之wxapp視圖容器 scroll-view
這篇文章主要介紹了微信小程序 教程之wxapp視圖容器 scroll-view的相關資料,需要的朋友可以參考下2016-10-10
JS面試中你不知道的call apply bind方法及使用場景詳解
這篇文章主要為大家介紹了JS面試中你不知道的call apply bind方法及使用場景詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-02-02

