欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2007年12月16日 21:31:02   投稿:mdxy-dxy  
javascript來實現(xiàn)動畫導航效果是通過定時器與鼠標事件響應相結(jié)合,動態(tài)修改頁面元素屬性實現(xiàn)的動畫導航效果,需要的朋友可以參考一下

誰在用這些導航
google是個大公司,全世界都有google的腳印,韓國的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>

演示地址

相關文章

最新評論