Our new tutorial tells about developing cool musical drop down menu (html5 + css3). This menu has css3 animation effects (neat hover effect to menu elements). We also used html5 Audio element in order to add music to this menu. If you are ready, lets start.
Step 1. HTML
As the first, we should prepare HTML layout of our menu. Each menu element (which actually is a unordered list item) has anchor, or nested level.
02 | < li >< a href = "#" >Menu element</ a > |
04 | < li >< a href = "#" >Submenu element</ a ></ li > |
08 | < li >< a href = "#" >Menu 4</ a ></ li > |
Step 2. CSS
Here are the CSS styles of our menu:
002 | list-style : none outside none ; |
007 | font-family : "Lucida Sans Unicode" , Verdana , Arial , sans-serif ; |
010 | list-style : none outside none ; |
012 | text-shadow : 0 -1px 3px #202020 ; |
016 | -moz-border-radius: 4px ; |
017 | -webkit-border-radius: 4px ; |
021 | -moz-box-shadow: 0px 3px 3px #cecece ; |
022 | -webkit-box-shadow: 0px 3px 3px #cecece ; |
023 | box-shadow: 0 3px 4px #8b8b8b ; |
026 | background-image : -webkit-gradient(linear, left bottom , left top , color-stop( 0 , #787878 ), color-stop( 0.5 , #5E5E5E ), color-stop( 0.51 , #707070 ), color-stop( 1 , #838383 )); |
027 | background-image : -moz-linear-gradient( center bottom , #787878 0% , #5E5E5E 50% , #707070 51% , #838383 100% ); |
028 | background-color : #5f5f5f ; |
031 | border-bottom : 1px solid #575757 ; |
032 | border-left : 1px solid #929292 ; |
033 | border-right : 1px solid #5d5d5d ; |
034 | border-top : 1px solid #797979 ; |
041 | #nav > li:first-child { |
052 | background : none repeat scroll 0 0 #838383 ; |
053 | box-shadow: 5px 5px 5px rgba( 0 , 0 , 0 , 0.5 ); |
060 | outline : medium none ; |
062 | text-decoration : none ; |
065 | background-image : -webkit-gradient(linear, left bottom , left top , color-stop( 0 , #787878 ), color-stop( 0.5 , #5E5E5E ), color-stop( 0.51 , #707070 ), color-stop( 1 , #838383 )); |
066 | background-image : -moz-linear-gradient( center bottom , #787878 0% , #5E5E5E 50% , #707070 51% , #838383 100% ); |
067 | background-color : #5f5f5f ; |
071 | @-webkit-keyframes animation { |
073 | -webkit-transform: scale( 1 ); |
076 | -webkit-transform: scale( 1.2 ); |
079 | -webkit-transform: scale( 1.1 ); |
082 | @-moz-keyframes animation { |
084 | -moz-transform: scale( 1 ); |
087 | -moz-transform: scale( 1.2 ); |
090 | -moz-transform: scale( 1.1 ); |
095 | -webkit-animation-name: animation; |
096 | -webkit-animation-duration: 0.3 s; |
097 | -webkit-animation-timing-function: linear; |
098 | -webkit-animation-iteration-count: 1 ; |
099 | -webkit-animation- direction : normal ; |
100 | -webkit-animation-delay: 0 ; |
101 | -webkit-animation-play-state: running; |
102 | -webkit-animation-fill-mode: forwards; |
104 | -moz-animation-name: animation; |
105 | -moz-animation-duration: 0.3 s; |
106 | -moz-animation-timing-function: linear; |
107 | -moz-animation-iteration-count: 1 ; |
108 | -moz-animation- direction : normal ; |
109 | -moz-animation-delay: 0 ; |
110 | -moz-animation-play-state: running; |
111 | -moz-animation-fill-mode: forwards; |
When we hover over a list item, we will animate (scale) it once to emulate beat effect.
Step 3. HTML5 JavaScript
Now, it is time to add music here. In the beginning, we should prepare a new empty array (to keep our Audio objects), and then, when the page is ready, initialize the music:
05 | addEvent(window, 'load' , function (event) { |
08 | aLoops[0] = new Audio( 'media/background.ogg' ); |
09 | aLoops[0].volume = 0.3; |
10 | aLoops[1] = new Audio( 'media/button.ogg' ); |
11 | aLoops[1].volume = 1.0; |
12 | aLoops[2] = new Audio( 'media/button_click.ogg' ); |
13 | aLoops[2].volume = 1.0; |
15 | aLoops[0].addEventListener( 'ended' , function () { |
And then, we should add the handlers to different events: mouseover, mouseout and click:
02 | var aBtns = document.querySelectorAll( '#nav li' ); |
05 | addEvent(aBtns, 'mouseover' , function (event) { |
06 | aLoops[1].currentTime = 0; |
11 | addEvent(aBtns, 'mouseout' , function (event) { |
12 | aLoops[1].currentTime = 0; |
17 | addEvent(aBtns, 'click' , function (event) { |
18 | aLoops[2].currentTime = 0; |
And voila, we have finalized it.
Share this