当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 用javascript来实现动画导航效果的代码

Javascript
编辑浪子版表单验证类
JavaScript脚本语言在网页中的简单应用
getElementById在任意一款浏览器中都可以用吗的疑问回复
“增强js程序代码的健壮性”之我见大量示例代码
javascript之卸载鼠标事件的代码
静态页面下用javascript操作ACCESS数据库(读增改删)的代码
javascript操作文本框readOnly
用javascript实现gb2312转utf-8的脚本
网站被黑的假象--ARP欺骗之页面中加入一段js
(JS实现)MapBar中坐标的加密和解密的脚本
几款极品的javascript压缩混淆工具
[原创]由亿起发(eqifa.com)的页面发现顶部的http://16a.us/8.js想到的js解密
JavaScript中的new的使用方法与注意事项
分别用两个函数实现的菜单
非常不错的模拟打字效果,目前仅支持纯文本、BR标签、和P标签
用javascript实现的支持lrc歌词的播放器
JS加ASP二级域名转向的代码
效果直逼flash的Div+Css+Js菜单
input之怎么清除默认值
用xhtml+css写的相册自适应 - 类似九宫格[兼容 ff ie6 ie7 opear ]

Javascript 中的 用javascript来实现动画导航效果的代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 99 ::
收藏到网摘: n/a

谁在用这些导航
google是个大公司,全世界都有google的脚印,韩国的google动画效果非常不错,蓝色理想论坛里已经有人挖过来了,可惜js写的太多了,那自己写一个吧?好,就这么干!
原理
小时候,总喜欢看动画片吧,动画片是怎样实现的呢?记得妈妈说是一张画一张画切换过去(啊?那一部葫芦兄弟要画多少副画啊? -_-! ),其实我们现在做的也是这样,用一个图片,这个图片里有很多个小图,来显示动画轨迹.按时间来移动图片,那图片不是会动了啊?(不知道,表达清楚了没…语文很重要啊!!)
准备
我们需要一张图片,一个大脑,一张会笑的脸(不笑效果就出不来了….)!!下面是我准备的图片(ps水平有限^_^)…

代码
我们看到上面的图片,想象下,它动起来是多么的优美啊…
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){
//初始化一些参数
this.iImgNum=7; //小图片个数
this.iImgHeight=75; //小图片高度
this.iOverSpeed=50; //鼠标经过时候切换的时间
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(){//鼠标经过
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(){//经过图片位置递增
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(){////经过图片位置递减
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>

演示地址