JS下拉緩沖菜單示例代碼
更新時(shí)間:2013年08月30日 16:34:32 作者:
下拉緩沖菜單效果想必大家都有見(jiàn)過(guò)吧,在本文使用JS輕松實(shí)現(xiàn)下,想學(xué)習(xí)的朋友可以參考下
復(fù)制代碼 代碼如下:
<!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下拉緩沖菜單_網(wǎng)頁(yè)代碼站()</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">草帽海賊團(tuán)船長(zhǎng),特征是頭戴草帽,天性樂(lè)觀、熱情、善良、天真、單純。</span>
</li>
<li style="background:url('/images/20130826/psb1.png')">
<a href="#">索隆</a>
<img src="/images/20130826/psb2.jpg" class="map" />
<span class="content">草帽海賊團(tuán)劍士,綠色頭發(fā),左耳戴三只黃色露珠耳環(huán),綠色的肚兜,路癡。</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">精通氣象學(xué)和航海術(shù),擅長(zhǎng)偷術(shù)、騙術(shù)、談判及威脅恐嚇,頭腦聰明又機(jī)靈。</span>
</li>
<li style="background:url('/images/20130826/psb1.png')">
<a href="#">山治</a>
<img src="/images/20130826/psb4.jpg" class="map" />
<span class="content">草帽海賊團(tuán)廚師,金發(fā),有著卷曲眉毛,永遠(yuǎn)遮住半邊臉的家伙,海賊中的紳士。</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>
您可能感興趣的文章:
- js實(shí)現(xiàn)div彈出層的方法
- 使用js實(shí)現(xiàn)關(guān)閉js彈出層的窗口
- js 點(diǎn)擊頁(yè)面其他地方關(guān)閉彈出層(示例代碼)
- js點(diǎn)擊任意區(qū)域彈出層消失實(shí)現(xiàn)代碼
- 使用JavaScript實(shí)現(xiàn)彈出層效果的簡(jiǎn)單實(shí)例
- JS+CSS實(shí)現(xiàn)鼠標(biāo)經(jīng)過(guò)彈出一個(gè)DIV框完整實(shí)例(帶緩沖動(dòng)畫(huà)漸變效果)
- js實(shí)現(xiàn)隨屏幕滾動(dòng)的帶緩沖效果的右下角廣告代碼
- js實(shí)現(xiàn)緩沖運(yùn)動(dòng)效果的方法
- JS實(shí)現(xiàn)多物體緩沖運(yùn)動(dòng)實(shí)例代碼
- JS實(shí)現(xiàn)側(cè)邊欄鼠標(biāo)經(jīng)過(guò)彈出框+緩沖效果
相關(guān)文章
Bootstrap每天必學(xué)之標(biāo)簽頁(yè)(Tab)插件
Bootstrap每天必學(xué)之標(biāo)簽頁(yè)(Tab)插件,通過(guò)這個(gè)插件您可以把內(nèi)容放置在標(biāo)簽頁(yè)或者是膠囊式標(biāo)簽頁(yè)甚至是下拉菜單標(biāo)簽頁(yè)中,感興趣的小伙伴們可以參考一下2016-04-04
Electron?自定義窗口桌面時(shí)鐘實(shí)現(xiàn)示例詳解
這篇文章主要為大家介紹了Electron?自定義窗口桌面時(shí)鐘實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03
JavaScript實(shí)現(xiàn)動(dòng)態(tài)表格效果
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)動(dòng)態(tài)表格效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-06-06
微信小程序教程系列之設(shè)置標(biāo)題欄和導(dǎo)航欄(7)
這篇文章主要為大家詳細(xì)介紹了微信小程序教程系列之標(biāo)題欄和導(dǎo)航欄的設(shè)置,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04
ant-design-pro使用qiankun微服務(wù)配置動(dòng)態(tài)主題色的問(wèn)題
這篇文章主要介紹了ant-design-pro使用qiankun微服務(wù)配置動(dòng)態(tài)主題色,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-03-03
JS對(duì)象與json字符串格式轉(zhuǎn)換實(shí)例
這篇文章主要介紹了JS對(duì)象與json字符串格式轉(zhuǎn)換方法,以實(shí)例的形式詳細(xì)講述了js對(duì)象與json字符串格式轉(zhuǎn)換的技巧,需要的朋友可以參考下2014-10-10

