用javascript來實(shí)現(xiàn)動畫導(dǎo)航效果的代碼
誰在用這些導(dǎo)航
google是個大公司,全世界都有g(shù)oogle的腳印,韓國的google動畫效果非常不錯,藍(lán)色理想論壇里已經(jīng)有人挖過來了,可惜js寫的太多了,那自己寫一個吧?好,就這么干!
原理
小時候,總喜歡看動畫片吧,動畫片是怎樣實(shí)現(xiàn)的呢?記得媽媽說是一張畫一張畫切換過去(啊?那一部葫蘆兄弟要畫多少副畫啊? -_-! ),其實(shí)我們現(xiàn)在做的也是這樣,用一個圖片,這個圖片里有很多個小圖,來顯示動畫軌跡.按時間來移動圖片,那圖片不是會動了啊?(不知道,表達(dá)清楚了沒…語文很重要啊!!)
準(zhǔn)備
我們需要一張圖片,一個大腦,一張會笑的臉(不笑效果就出不來了….)!!下面是我準(zhǔn)備的圖片(ps水平有限^_^)…

代碼
我們看到上面的圖片,想象下,它動起來是多么的優(yōu)美啊…
css
.Gnb_btn_div{
width:90px;
height:75px;
overflow:hidden;
display:block;
position:absolute;
}
.Gnb_btn_img{
width:100%;
height:525px;
display:block;
overflow:hidden;
text-indent:-500px;
}
#gnb_btn_01 .Gnb_btn_img {
background-image:url(http://www.wler.cn/blog/img/friend.gif)
}
javascript
<script type="text/javascript">
// <![CDATA[
function GNB(_7c){
//初始化一些參數(shù)
this.iImgNum=7; //小圖片個數(shù)
this.iImgHeight=75; //小圖片高度
this.iOverSpeed=50; //鼠標(biāo)經(jīng)過時候切換的時間
this.iOutSpeed=50; //鼠標(biāo)離開時候切換的時間
this.eventObj=_7c; //取得圖片對象
this.MouseOverFlag=false;
this.imageIndex=0;
if(this.eventObj==null){return;}
this.eventObj.parentClass=this;this.eventAssign();
}
GNB.prototype.eventAssign=function(){//注冊事件
this.eventObj.onmouseover=this.menuMouseOver;
this.eventObj.onmouseout=this.menuMouseOut;
};
GNB.prototype.menuMouseOver=function(){//鼠標(biāo)經(jīng)過
if(this.parentClass.MouseOverFlag!=false){return;}
this.parentClass.MouseOverFlag=true;
this.parentClass.clearTimeOut();
this.parentClass.menuMouseOverTimer();
};
GNB.prototype.menuMouseOut=function(){//鼠標(biāo)離開
this.parentClass.MouseOverFlag=false;
this.parentClass.clearTimeOut();
this.parentClass.menuMouseOutTimer();
};
GNB.prototype.menuMouseOverTimer=function(){//經(jīng)過圖片位置遞增
var _7d=this;
if(this.imageIndex>=this.iImgNum){return;}
this.eventObj.scrollTop=this.imageIndex*this.iImgHeight;
this.imageIndex++;
this.setTimerID=setTimeout(function(){_7d.menuMouseOverTimer();},this.iOverSpeed);
};
GNB.prototype.menuMouseOutTimer=function(){////經(jīng)過圖片位置遞減
var _7e=this;if(this.imageIndex<0){return;}
this.eventObj.scrollTop=this.imageIndex*this.iImgHeight;
this.imageIndex--;
this.setTimerID=setTimeout(function(){_7e.menuMouseOutTimer();},this.iOutSpeed);
};
GNB.prototype.clearTimeOut=function(){//取消定時
clearTimeout(this.setTimerID);
};
// ]]>
</script>
xhtml
<div class="Gnb_btn_div" id="gnb_btn_01">
<a class="Gnb_btn_img" href="#1" href="#1">找朋友</a>
</div>
<script type="text/javascript">
// <![CDATA[
var GNB1=new GNB(document.getElementById("gnb_btn_01"));//實(shí)例單個按鈕,當(dāng)然也可以多個
// ]]>
</script>
演示地址
- javascript 樹形導(dǎo)航菜單實(shí)例代碼
- JavaScript NodeTree導(dǎo)航欄(菜單項(xiàng)JSON類型/自制)
- javascript實(shí)現(xiàn)的鼠標(biāo)懸停時動態(tài)翻滾的導(dǎo)航條
- javascript實(shí)現(xiàn)的又一個不錯的滑動導(dǎo)航效果
- js實(shí)現(xiàn)多選項(xiàng)切換導(dǎo)航菜單的方法
- 一個js控制的導(dǎo)航菜單實(shí)例代碼
- js左側(cè)三級菜單導(dǎo)航實(shí)例代碼
- JavaScript實(shí)現(xiàn)簡單的二級導(dǎo)航菜單實(shí)例
相關(guān)文章
在JavaScript中終止forEach循環(huán)的三種方式
如何終止forEach循環(huán)這個問題估計(jì)會難倒一部分同學(xué),甚至?xí)腥朔磫?forEach循環(huán)在JavaScript中能終止嗎?本文小編給大家介紹了三種方式可以終止forEach循環(huán),需要的朋友可以參考下2023-11-11
JS簡單獲取客戶端IP地址的方法【調(diào)用搜狐接口】
這篇文章主要介紹了JS簡單獲取客戶端IP地址的方法,通過調(diào)用搜狐接口來簡單實(shí)現(xiàn)獲取訪客IP地址的功能,非常簡便實(shí)用,需要的朋友可以參考下2016-09-09
使用JS location實(shí)現(xiàn)搜索框歷史記錄功能
這篇文章主要介紹了使用JS location實(shí)現(xiàn)搜索框歷史記錄功能,本文通過實(shí)例 代碼講解的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-12-12
讓div層隨鼠標(biāo)移動的實(shí)現(xiàn)代碼 ie ff
隨鼠標(biāo)移動的div層使用ie ff ,大家可以注意下兼容性的問題。2009-12-12
Bootstrap Paginator+PageHelper實(shí)現(xiàn)分頁效果
這篇文章主要為大家詳細(xì)介紹了Bootstrap Paginator+PageHelper實(shí)現(xiàn)分頁效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-12-12

