JS下拉缓冲菜单示例代码

 更新时间:2013年08月30日 16:34:32   作者:  
下拉缓冲菜单效果想必大家都有见过吧,在本文使用JS轻松实现下,想学习的朋友可以参考下
复制代码 代码如下:

<!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>
<style>
body,html,div,ul,li,span,img,a{
margin:0;
padding:0;
}
a{
text-decoration:none;
color:#000;
font-weight:bold;
width:150px;
display:inline-block;
text-align:center;
}
li{
list-style:none;
}
img{
width:0;
height:0;
outline:none;
}
#tab{
margin:200px 0 0 300px;
}
#tab li{
float:left;
width:150px;
height:50px;
line-height:50px;
position:relative;
margin-right:30px;
}
#tab img.map,#tab span.content{
position:absolute;
}
#tab span.content{
background:#333;
color:#FFF;
font-size:14px;
text-align:center;
height:0;
}
#tab img.map{
left:50%;
bottom:0;
}
</style>
<title>JS下拉缓冲菜单_网页代码站()</title>
</head>

<body>
<div id="tab">
<ul>
<li style="background:url('/images/20130826/psb1.png')">
<a href="#">路飞</a>
<img src="/jscss/demoimg/201210/psb1.jpg" class="map" />
<span class="content">草帽海贼团船长,特征是头戴草帽,天性乐观、热情、善良、天真、单纯。</span>
</li>
<li style="background:url('/images/20130826/psb1.png')">
<a href="#">索隆</a>
<img src="/images/20130826/psb2.jpg" class="map" />
<span class="content">草帽海贼团剑士,绿色头发,左耳戴三只黄色露珠耳环,绿色的肚兜,路痴。</span>
</li>
<li style="background:url('/images/20130826/psb1.png')">
<a href="#">娜美</a>
<img src="/jscss/demoimg/201210/psb3.jpg" class="map" />
<span class="content">精通气象学和航海术,擅长偷术、骗术、谈判及威胁恐吓,头脑聪明又机灵。</span>
</li>
<li style="background:url('/images/20130826/psb1.png')">
<a href="#">山治</a>
<img src="/images/20130826/psb4.jpg" class="map" />
<span class="content">草帽海贼团厨师,金发,有着卷曲眉毛,永远遮住半边脸的家伙,海贼中的绅士。</span>
</li>
</ul>
</div>
<script type="text/javascript">
function kzxf_zoom(id)
{
this.initialize.apply(this, arguments)
}

kzxf_zoom.prototype =
{
initialize : function()

{

var _this = this;
this.wrapBox = document.getElementById('tab');
this.oLi = this.wrapBox.getElementsByTagName('li');
this.aImg = this.wrapBox.getElementsByTagName('img');
this.content = this.wrapBox.getElementsByTagName('span');
for(var i=0;i<this.oLi.length;i++)
{
(function(i){
_this.oLi[i].onmouseover = function()

{
_this.jump(_this.aImg[i], _this.content[i]);

};
_this.oLi[i].onmouseout = function()

{
_this.hidden(_this.aImg[i], _this.content[i]);

};

})(i)

}

},
jump : function(obj1, obj2)

{

var _this = this;
_this.animation(obj1, {height:130, width:160, marginLeft:-78, marginTop:-128},function(){
_this.animation(obj1, {height:115, width:140, marginLeft:-70, marginTop:-115}, function(){
_this.animation(obj1, {height:120, width:150, marginLeft:-75, marginTop:-120})
})
});
_this.animation(obj2, {height:200});
},
hidden : function(obj1, obj2)
{
var _this = this;
_this.animation(obj1, {width:0, height:0, marginLeft:0, marginTop:0});
_this.animation(obj2, {height:0});
},
animation : function(obj, oAttr, fnCallBack)
{
var _this = this;
clearInterval(obj.timer);
obj.timer = setInterval(function()
{
var bStop = true;
for(proper in oAttr)
{

var iCur = parseFloat(_this.css(obj, proper));

proper == 'opacity' && (iCur = parseInt(iCur.toFixed(2) * 100));

var iSpeed = (oAttr[proper] - iCur) / 5;

iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);

if(iCur != oAttr[proper])

{

bStop = false;

_this.css(obj, proper, iCur + iSpeed);

}

}

if(bStop)

{

clearInterval(obj.timer);

fnCallBack && fnCallBack.apply(_this, arguments);

}

},20);

},

css : function(obj, attr, value)

{

if(arguments.length == 2)

{

return obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj, null)[attr]

}

if(arguments.length == 3)

{

switch(attr)

{

case 'width' :

case 'height' :

case 'top' :

case 'bottom' :

case 'left' :

case 'marginLeft':

case 'marginTop':

obj.style[attr] = value + 'px';

break;

case 'opacity' :

obj.style.filter = 'alpha(opacity = '+value+' )';

obj.style.opacity = value / 100;

break;

default :

obj.style[attr] = value;

break;

}

}

}

};
window.onload = function()
{
new kzxf_zoom('tab')

};

</script>
<br />
http://user.qzone.qq.com/1198772766
</body>
</html>

相关文章

  • Bootstrap每天必学之标签页(Tab)插件

    Bootstrap每天必学之标签页(Tab)插件

    Bootstrap每天必学之标签页(Tab)插件,通过这个插件您可以把内容放置在标签页或者是胶囊式标签页甚至是下拉菜单标签页中,感兴趣的小伙伴们可以参考一下
    2016-04-04
  • JavaScript获得选中文本内容的方法

    JavaScript获得选中文本内容的方法

    今天希望实现一个,直接在网页上选中文本,点击收藏夹的链接(javascript)即可弹出新窗口(类似“百度搜藏”和“QQ书签”),新窗口中的文本框即显示了选中的文本。
    2008-12-12
  • Electron 自定义窗口桌面时钟实现示例详解

    Electron 自定义窗口桌面时钟实现示例详解

    这篇文章主要为大家介绍了Electron 自定义窗口桌面时钟实现示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-03-03
  • JavaScript实现动态表格效果

    JavaScript实现动态表格效果

    这篇文章主要为大家详细介绍了JavaScript实现动态表格效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-06-06
  • 微信小程序教程系列之设置标题栏和导航栏(7)

    微信小程序教程系列之设置标题栏和导航栏(7)

    这篇文章主要为大家详细介绍了微信小程序教程系列之标题栏和导航栏的设置,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-04-04
  • ant-design-pro使用qiankun微服务配置动态主题色的问题

    ant-design-pro使用qiankun微服务配置动态主题色的问题

    这篇文章主要介绍了ant-design-pro使用qiankun微服务配置动态主题色,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-03-03
  • JS+Canvas 实现下雨下雪效果

    JS+Canvas 实现下雨下雪效果

    本文给大家介绍基于JS+Canvas 实现下雨下雪效果,效果非常逼真,适应于各大网站,需要的朋友可以参考下
    2016-05-05
  • 详解iframe跨域的几种常用方法(小结)

    详解iframe跨域的几种常用方法(小结)

    这篇文章主要介绍了详解iframe跨域的几种常用方法(小结),小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2019-04-04
  • JS操作HTML自定义属性的方法

    JS操作HTML自定义属性的方法

    这篇文章主要介绍了JS操作HTML自定义属性的方法,以实例形式分析了html中自定义属性的设置与对应的javascript操作技巧,非常具有实用价值,需要的朋友可以参考下
    2015-02-02
  • JS对象与json字符串格式转换实例

    JS对象与json字符串格式转换实例

    这篇文章主要介绍了JS对象与json字符串格式转换方法,以实例的形式详细讲述了js对象与json字符串格式转换的技巧,需要的朋友可以参考下
    2014-10-10

最新评论