jquery 插件之仿“卓越亞馬遜”首頁彈出菜單效果
更新時間:2008年12月25日 14:46:26 作者:
用jquery實現(xiàn)的彈出菜單插件
復制代碼 代碼如下:
/*彈出式菜單*/
//沒劍 2008-07-03
//http://regedit.cnblogs.com
/*參數(shù)說明*/
//showobj:要顯示的菜單ID
//timeout:延時時間,鼠標停留/離開后延時多久開始顯示/隱藏菜單
//speed:菜單顯示速度,數(shù)字越大,顯示越慢,默認為100
//調(diào)用示例:$("#button").DMenu("#content");
jQuery.fn.DMenu=function(showobj,timeout,speed){
timeout=timeout?timeout:300;
speed=speed?speed:100;
//按鈕對象
var button=$(this);
//延時計數(shù)器
var timer=null;
//隱藏的浮動層
var hideDiv=$("<div></div>");
//容器對象
var Container=$("<div id=\"Container\"></div>");
Container.hide();
hideDiv.append(Container);
//菜單對象
var jqShowObj=$(showobj);
//隱藏菜單
jqShowObj.hide();
//菜單顯示的狀態(tài)
var display=false;
//按鈕的offset
var offset=button.offset();
//菜單區(qū)高
var height=jqShowObj.height();
//菜單區(qū)寬
var width=jqShowObj.width();
//按鈕的高
var btnHeight=button.height();
//按鈕的寬
var btnWidth=button.width();
//定位層放到最前面
$(document.body).prepend(hideDiv);
//放到容器中
//Container.append(jqShowObj);
//****顯示菜單方法開始****//
var showMenu=function(){
//如果菜單為顯示則退出操作
if (display)
{
return false;
}
//設(shè)置容器屬性
Container.css({
margin:"0 auto",
width:btnWidth+"px",
height:btnHeight+"px"
});
//定位隱藏層
hideDiv.css({
position:"absolute",
top:offset.top+"px",
left:offset.left+(btnWidth/2)-(width/2)+"px",
height:height+"px",
width:width+"px"
}).show();
//給容器加個黑邊框
Container.css({
border:"1px solid #666666"
});
//顯示定位層
//高寬慢慢增大
Container.animate({
marginTop:btnHeight+4,
height:height+4,
width:width+4,
opacity:'100'},speed,function(){
//動畫結(jié)束時 start//
//顯示菜單
jqShowObj.show();
//添加菜單入容器
Container.append(jqShowObj);
//去除邊框
Container.css({
border:"0px"
});
//顯示狀態(tài)置為true
display=true;
//鼠標移入
jqShowObj.mouseover(function(){
clearTimeout(timer);
});
//鼠標移開
jqShowObj.mouseout(function(){
hideMenu();
});
//動畫結(jié)束時 end//
});
};
//****顯示菜單方法結(jié)束****//
//****隱藏菜單方法開始****//
var hideMenu=function(){
clearTimeout(timer);
//延時隱藏菜單
timer=setTimeout(function(){
//顯示邊框
Container.css({
border:"1px solid #666666"
});
//清空容器
Container.empty();
//收縮容器
Container.animate({
width:btnWidth,height:btnHeight,marginTop:'0', opacity: '0'
}, speed,function(){
//動畫結(jié)束時 start//
//隱藏容器
Container.hide();
//定位層隱藏
hideDiv.hide();
//顯示狀態(tài)置為false
display=false;
//動畫結(jié)束時 end//
});
}, timeout);
};
//****隱藏菜單方法結(jié)束****//
//綁定按鈕鼠標經(jīng)過事件
button.hover(function(e){
//延時顯示菜單
clearTimeout(timer);
timer=setTimeout(function(){
showMenu();
}, timeout);
},function(){
clearTimeout(timer);
//鼠標離開按鈕時,如果菜單還是顯示狀態(tài)則隱藏
if(display){
timer=setTimeout(function(){
hideMenu();
},timeout);
}
});
};
注:對于select擋住彈出菜單的問題,因為與插件沒有關(guān)系,所以在此,偶沒有解決,放哪個select在哪只是想提醒大家使用彈出菜單時要注意到這個問題,具體的解決方法可以自動搜索,或者在排版上作調(diào)整。
文件打包下載
您可能感興趣的文章:
相關(guān)文章
基于jQuery的$.getScript方法去加載javaScript文檔解析
下面小編就為大家?guī)硪黄趈Query的$.getScript方法去加載javaScript文檔解析。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-11-11
ie8模式下click無反應(yīng)點擊option無反應(yīng)的解決方法
點擊select里面的option,將其賦值到上面的input,直接用jQuery寫的,問題是在用IE8打開的時候,點擊option沒有任何反應(yīng)2014-10-10
淺談jQuery this和$(this)的區(qū)別及獲取$(this)子元素對象的方法
下面小編就為大家?guī)硪黄獪\談jQuery this和$(this)的區(qū)別及獲取$(this)子元素對象的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-11-11
jquery ajax結(jié)合thinkphp的getjson實現(xiàn)跨域的方法
這篇文章主要介紹了jquery ajax結(jié)合thinkphp的getjson實現(xiàn)跨域的方法,結(jié)合實例形式對比分析了jQuery ajax實現(xiàn)跨域的具體操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下2016-06-06
使用jQuery向asp.net Mvc傳遞復雜json數(shù)據(jù)-ModelBinder篇
jQuery提供的ajax方法能很方便的實現(xiàn)客戶端與服務(wù)器的異步交互,在asp.net mvc 框架使用jQuery能很方便地異步獲取提交數(shù)據(jù),給用戶提供更好的體驗!2010-05-05

