jQuery New Top Black Menu Bar like Google
2013-05-17 22:26
330 查看
71
GooglehascomeupwithanewlookwiththelaunchofGooglePlusandoneoftheprominentchangeswecanobserveistheblackmenubarfoundonthetopofGoogleSearchPageandeveryotherGoogleproductlikeGooglePlus(obviously),Googlereader,etc.AlmosteveryGoogleproductbynowhasbeenintegratedwiththetopblackmenubar.
IntroducingthismenubarlookslikeamovebyGoogletointegrateGooglePluswithallotherGoogleproducts.
IthoughtitwouldbeagreatideatomakeatutorialonhowtocreatethisblackmenubarusingsimplejQueryandCSS.
SomeofthefeatureswearegoingtocoverinthistutorialofmakingTopMenuBarfoundinGoogleproductsis:
Creatingtheredribbonlikeeffectforthecurrentpage
creatingthedropdownmenuwhenmorebuttonisclicked
keepingthebarfixedevenwhentherestofthepageisscrolled
StylingtheelementsofthemenuexactlytothosefoundonGoogle
CSS
body{ |
padding : 0 ; |
margin : 0 ; |
} |
.menu{ |
position : fixed ; |
top : 0 ; |
left : 0 ; |
width : 100% ; |
font : 13px / 27px Arial , sans-serif ; |
color : #3366cc ; |
height : 30px ; |
background : #2D2D2D ; |
} |
.menua:hover{ |
background-color : #676767 ; |
color : #CCCCCC ; |
} |
.menua{ |
text-decoration : none ; |
padding : 6px 8px 7px ; |
color : #CCCCCC ; |
outline : none ; |
} |
.menuul{ |
list-style : none ; |
margin : 0 ; |
padding : 0 0 0 10px ; |
} |
.menuulli{ |
padding : 0 ; |
float : left ; |
} |
.menuulliulli{ |
padding : 0 ; |
float : none ; |
margin : 0 0 0 0px ; |
width : 100% ; |
} |
.menuulliul{ |
position : absolute ; |
border : 1px solid #C3D1EC ; |
/*box-shadow*/ |
-webkit-box-shadow: 0 1px 5px #CCCCCC ; |
-moz-box-shadow: 0 1px 5px #CCCCCC ; |
box-shadow: 0 1px 5px #CCCCCC ; |
margin-top : -1px ; |
display : none ; |
padding : 0px 16px 0px 0 ; |
} |
.activeul{ |
display : block !important ; |
} |
.singleul{ |
display : block !important ; |
} |
.activea{ |
background-color : white ; |
border : 1px solid #C3D1EC ; |
border-bottom : 0 ; |
/*box-shadow*/ |
-webkit-box-shadow: 0 -1px 5px #CCCCCC ; |
-moz-box-shadow: 0 -1px 5px #CCCCCC ; |
box-shadow: 0 -1px 5px #CCCCCC ; |
display : block ; |
height : 29px ; |
padding : 0 8px 0 8px ; |
position : relative ; |
z-index : 1 ; |
color : #3366CC ; |
} |
/*Stylingforthelinkofthecurrentpage*/ |
.currenta{ |
background-color : #2D2D2D ; |
border-top : 2px solid #DD4B39 ; /*redribbonattop*/ |
border-bottom : 0 ; |
display : block ; |
height : 25px ; |
padding : 0 8px 0 8px ; |
position : relative ; |
z-index : 1 ; |
color : #FFFFFF ; |
font-weight : bold ; |
} |
.activea:hover{ |
background-color : white ; |
color : #3366CC ; |
} |
.activeula:hover{ |
background-color : #e4ebf8 ; |
} |
.activeula{ |
border : 0 !important ; |
/*box-shadow*/ |
-webkit-box-shadow: 0 0 0 #CCCCCC ; |
-moz-box-shadow: 0 0 0 #CCCCCC ; |
box-shadow: 0 0 0 #CCCCCC ; |
border : 0 ; |
width : 100% ; |
} |
.arrow{ |
border-color : #C0C0C0 transparent white ; |
border-style : solid dashed dashed ; |
margin-left : 5px ; |
position : relative ; |
top : 10px ; |
} |
.mid-line{ |
background-color : #FFF ; |
border-top : 1px solid #e5e5e5 ; |
font-size : 0 ; |
} |
Javascript
$( function ($){ |
$.fn.fixedMenu= function (){ |
return this .each( function (){ |
var menu=$( this ); |
//closedropdownwhenclickedanywhereelseonthedocument |
$( "html" ).click( function (){ |
menu.find( '.active' ).removeClass( 'active' ); |
}); |
menu.find( 'ulli>a' ).bind( 'click' , function (event){ |
event.stopPropagation(); |
//checkwhethertheparticularlinkhasadropdown |
if (!$( this ).parent().hasClass( 'single-link' )&&!$( this ).parent().hasClass( 'current' )){ |
//hidingdropdownmenuwhenitisclickedagain |
if ($( this ).parent().hasClass( 'active' )){ |
$( this ).parent().removeClass( 'active' ); |
} else { |
//displayingthedropdownmenu |
$( this ).parent().parent().find( '.active' ).removeClass( 'active' ); |
$( this ).parent().addClass( 'active' ); |
} |
} else { |
//hidingthedropdownmenuwhensomeotherlinkisclicked |
$( this ).parent().parent().find( '.active' ).removeClass( 'active' ); |
} |
}) |
}); |
} |
})(jQuery); |
相关文章推荐
- Creating a Google Like RedBlack Navigation Bar Without Any Image/JavaScript
- Custom Swing Menu Bar with Web-Like Appearance & Behavior
- IOS横向菜单(TopBar Menu)代码示例 - XNScrollTopBar
- there is no examin menu in the top tool bar
- kendo ui PanelBar menu jquery 操作
- 反编译 解密 google tool bar 的PageRank
- <Android开源库> Google 最新Hover Menu(悬浮菜单)
- jquery源码解析:proxy,access,swap,isArraylike详解
- Google Round B China New Grad Test 2014
- 【NLP新闻-2013.05.15】How Google is setting the new search standard with voice and knowledge graph
- 使用jQuery模拟Google的自动提示效果
- jquery scrollTop 不起效果的一种情况
- Google Puts New Anti-Phishing Measures Into Gmail @ JDJ
- 主流JavaScript框架(Dojo、Google Closure、jQuery、Prototype、Mootools和YUI)的分析和对比
- jquery.newplaceholder.js
- 使用ActionManager, ActionMainMenuBar, ActionToolBar制作菜单
- PocketPC2003上使用SHCreateMenuBar进行菜单显示的问题解决
- Sharepoint 2013 页面置顶(Topbar)小插件
- jQuery offset方法结合easyui-menu进行使用
- 安卓界面篇(一) 自定义一个topbar