色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

用javascript來實現(xiàn)動畫導航效果的代碼

誰在用這些導航
google是個大公司,全世界都有g(shù)oogle的腳印,韓國的google動畫效果非常不錯,藍色理想論壇里已經(jīng)有人挖過來了,可惜js寫的太多了,那自己寫一個吧?好,就這么干!
原理
小時候,總喜歡看動畫片吧,動畫片是怎樣實現(xiàn)的呢?記得媽媽說是一張畫一張畫切換過去(啊?那一部葫蘆兄弟要畫多少副畫啊? -_-! ),其實我們現(xià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;        //鼠標經(jīng)過時候切換的時間 
    this.iOutSpeed=50;        //鼠標離開時候切換的時間 
    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(){//鼠標經(jīng)過 
    if(this.parentClass.MouseOverFlag!=false){return;} 
    this.parentClass.MouseOverFlag=true; 
    this.parentClass.clearTimeOut(); 
    this.parentClass.menuMouseOverTimer(); 
};      

GNB.prototype.menuMouseOut=function(){//鼠標離開 
    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"));//實例單個按鈕,當然也可以多個 
// ]]> 
</script>

演示地址

JavaScript技術(shù)用javascript來實現(xiàn)動畫導航效果的代碼,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 邛崃市| 日土县| 剑川县| 潞西市| 桐梓县| 策勒县| 赫章县| 婺源县| 竹溪县| 靖边县| 盖州市| 城市| 扎鲁特旗| 双桥区| 炎陵县| 红安县| 绥江县| 内乡县| 邵阳县| 宁津县| 赞皇县| 玉林市| 社会| 宣威市| 岢岚县| 仲巴县| 平果县| 东乡族自治县| 石棉县| 高平市| 仪征市| 通山县| 常宁市| 茂名市| 武功县| 江川县| 成武县| 特克斯县| 洪洞县| 清新县| 永顺县|