In this tutorial we are going to make use  of the incredibly awesome rotating and scaling jQuery patch from Zachary  Johnson that can be found here. We will create a menu with little icons  that will rotate when hovering. Also, we will make the menu item expand  and reveal some menu content, ...

In this tutorial we are going to make use of the incredibly awesome rotating and scaling jQuery patch from Zachary Johnson that can be found here. We will create a menu with little icons that will rotate when hovering. Also, we will make the menu item expand and reveal some menu content, like links or a search box.
Ok, so let’s get started, it’s less complicated than it looks.
The Markup
For this menu we will not create a list, but div elements for each menu item. We will pack the menu items in a main div called menu. Each item will have an icon as link element and a content div with the heading and a paragraph where we will add links or a search box:| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | <divclass="menu">    <divclass="item">        <aclass="link icon_mail"></a>        <divclass="item_content">            <h2>Contact us</h2>            <p>                <ahref="#">eMail</a>                <ahref="#">Twitter</a>                <ahref="#">Facebook</a>            </p>        </div>    </div>    <divclass="item">        <aclass="link icon_help"></a>        <divclass="item_content">            <h2>Help</h2>            <p>                <ahref="#">FAQ</a>                <ahref="#">Live Support</a>                <ahref="#">Tickets</a>            </p>        </div>    </div>    <divclass="item">        <aclass="link icon_find"></a>        <divclass="item_content">            <h2>Search</h2>            <p>                <inputtype="text"></input>                <ahref="">Go</a>            </p>        </div>    </div>    <divclass="item">        <aclass="link icon_photos"></a>        <divclass="item_content">            <h2>Image Gallery</h2>            <p>                <ahref="#">Categories</a>                <ahref="#">Archives</a>                <ahref="#">Featured</a>            </p>        </div>    </div>    <divclass="item">        <aclass="link icon_home"></a>        <divclass="item_content">            <h2>Start from here</h2>            <p>                <ahref="#">Services</a>                <ahref="#">Portfolio</a>                <ahref="#">Pricing</a>            </p>        </div>    </div></div> | 
The CSS
The general style for the menu like the font will be defined as follows:| 1 2 3 4 5 6 7 8 9 10 11 12 | .menu{    width:800px;    height:52px;    position:relative;    top:200px;    left:100px;    font-family: "Trebuchet MS", sans-serif;    font-size: 16px;    font-style: normal;    font-weight: bold;    text-transform: uppercase;} | 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | .item{    position:relative;    background-color:#f0f0f0;    float:right;    width:52px;    margin:0px5px;    height:52px;    border:2pxsolid#ddd;    -moz-border-radius:30px;    -webkit-border-radius:30px;    border-radius:30px;    -moz-box-shadow:1px1px3px#555;    -webkit-box-shadow:1px1px3px#555;    box-shadow:1px1px3px#555;    cursor:pointer;    overflow:hidden;} | 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | .link{    left:2px;    top:2px;    position:absolute;    width:48px;    height:48px;}.icon_home{    background:transparenturl(../images/home.png) no-repeattopleft;}.icon_mail{    background:transparenturl(../images/mail.png) no-repeattopleft;}.icon_help{    background:transparenturl(../images/help.png) no-repeattopleft;}.icon_find{    background:transparenturl(../images/find.png) no-repeattopleft;}.icon_photos{    background:transparenturl(../images/photos.png) no-repeattopleft;} | 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | .item_content{    position:absolute;    height:52px;    width:220px;    overflow:hidden;    left:56px;    top:7px;    background:transparent;    display:none;}.item_content h2{    color:#aaa;    text-shadow: 1px1px1px#fff;    background-color:transparent;    font-size:14px;}.item_content a{    background-color:transparent;    float:left;    margin-right:7px;    margin-top:3px;    color:#bbb;    text-shadow: 1px1px1px#fff;    text-decoration:none;    font-size:12px;}.item_content a:hover{    color:#0b965b;}.item_content p {    background-color:transparent;    display:none;}.item_content p input{    border:1pxsolid#ccc;    padding:1px;    width:155px;    float:left;    margin-right:5px;} | 
Ok, let’s add some magic.
The JavaScript
First, we need to add the script inclusions of jQuery and the other two scripts of Zachary.Then we will add the following functions:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | $('.item').hover(    function(){        var$this= $(this);        expand($this);    },    function(){        var$this= $(this);        collapse($this);    });functionexpand($elem){    varangle = 0;    vart = setInterval(function() {        if(angle == 1440){            clearInterval(t);            return;        }        angle += 40;        $('.link',$elem).stop().animate({rotate: '+=-40deg'}, 0);    },10);    $elem.stop().animate({width:'268px'}, 1000)    .find('.item_content').fadeIn(400,function(){        $(this).find('p').stop(true,true).fadeIn(600);    });}functioncollapse($elem){    varangle = 1440;    vart = setInterval(function() {        if(angle == 0){            clearInterval(t);            return;        }        angle -= 40;        $('.link',$elem).stop().animate({rotate: '+=40deg'}, 0);    },10);    $elem.stop().animate({width:'52px'}, 1000)    .find('.item_content').stop(true,true).fadeOut()          .find('p').stop(true,true).fadeOut();} | 
The collapse function will rotate the icon back, decrease the width of the item and make the content disappear.
And that’s it! I hope you enjoyed it!
 






0 comments:
Post a Comment