Halftone Navigation Menu With jQuery & CSS3

22 January 2010 Friday

This application was viewed 1862 times




Halftone Navigation Menu With jQuery & CSS3

Providing an intuitive, yet eye-catching navigation on your site, is one of the ingredients for a great design. And with the performance improvements in newer browsers and the rise of JavaScript frameworks such as jQuery, it is becoming easier to include beautiful animations in your page designs.

Today we are making a CSS3 & jQuery halftone-style navigation menu, which will allow you to display animated halftone-style shapes in accordance with the navigation links, and will provide a simple editor for creating additional shapes as well.

View The DEMO

Step 1 – XHTML

The first step is to lay down the XHTML structure of the menu. The whole menu is positioned inside an unordered list UL, which is the most suitable way of organizing your site’s navigation. Inside each of the LI elements are the hyperlinks, that are later styled to look like buttons via some interesting CSS code that you will see in a moment.

demo.html

01.<div id="main">
02.  
03.<div id="navigation">
04.  
05.<ul class="menuUL">
06.<!-- The class names that are assigned to the links correspond to name of the shape that is shown on hover: -->
07.<li><a href="#" class="house">Home</a></li>
08.<li><a href="#" class="wrench">Services</a></li>
09.<li><a href="#" class="envelope">Contact</a></li>
10.<li><a href="#" class="info">About</a></li>
11.</ul>
12.  
13.<div class="clear"></div>
14.</div>
15.  
16.<div id="stage">
17.<!-- The dot divs are shown here -->
18.</div>
19.  
20.</div>

If you plan to use this menu on your site, you’ll first need to modify the href attributes, so that they correspond to your site’s structure.

Worth noticing are also the class names that are assigned to each of the links. Those are not used to style them, but rather to tell jQuery which shape to render.

Lastly, there is our #stage div, which is filled with special .dot divs that act as pixels for our shapes. You can create custom shapes by setting the menu in service mode, which is covered in step three.

Step 2 – CSS

It is time to add some life to the design, by specifying the CSS rules. I divided the style sheet in two parts. You can see the rest of the code in styles.css in the demonstration files.

styles.css – Part 1

01..menuUL li{
02.    /* This will arrange the LI-s next to each other */
03.    display:inline;
04.}
05.  
06..menuUL li a,.menuUL li a:visited{
07.    /* Styling the hyperlinks of the menu as buttons */
08.  
09.    float:left;
10.    font-weight:bold;
11.    background:url(img/button_bg.jpg) repeat-x center bottom #666666;
12.  
13.    /* display:block allows for additional CSS rules to take effect, such as paddings: */
14.    display:block;
15.    border:1px solid #4D4D4D;
16.    color:#CCCCCC;
17.    border-top-color:#565656;
18.  
19.    padding:4px 6px;
20.    margin:4px 5px;
21.    height:16px;
22.  
23.    /* Setting a CSS3 box shadow around the button */
24.  
25.    -moz-box-shadow:0 0 1px black;
26.    -webkit-box-shadow:0 0 1px black;
27.    box-shadow:0 0 1px black;
28.  
29.    /* CSS3 text shadow */
30.    text-shadow:0 1px black;
31.}
32.  
33..menuUL li a:hover{
34.    /* On hover show the top, lighter, part of the background: */
35.    background-position:center top;
36.    text-decoration:none;
37.}

In this first part, you can see that we are displaying the LI elements inline, which will arrange them one next to each other and thus allow us to form a horizontally oriented navigation menu in a compatible cross-browser fashion.

The hyperlinks inside them are displayed as block elements and floated to the left. Also some CSS3 rules are applied such as box-shadow, for casting a shadow under the buttons, and text-shadow, for shadows under the text of the button.

Those are all small details that contribute to the overall feel of the page, but are in no way compulsory for the browsing process. This is great for users whose browsers don’t support CSS3 yet (most notably the IE family).

styles.css – Part 2

01.#navigation{
02.    /* The navigation menu bar: */
03.    background:#222222;
04.    border:1px solid #111111;
05.    float:left;
06.    padding:5px 10px;
07.}
08.  
09.#navigation,.menuUL li a{
10.    /* CSS3 rounded corners for both the navigation bar and the buttons: */
11.    -moz-border-radius:4px;
12.    -webkit-border-radius:4px;
13.    -khtml-border-radius:4px;
14.    border-radius:4px;
15.}
16.  
17.#stage{
18.    /* The stage contains the individual divs that comprise the halftone icon: */
19.    height:300px;
20.    position:absolute;
21.    right:50px;
22.    top:20px;
23.    width:400px;
24.}
25.  
26..dot{
27.    /* The stage contains 192 .dot divs: */
28.    float:left;
29.    height:25px;
30.    width:25px;
31.}
32.  
33..dot.active{
34.    /* When assigned the active class, the div shows a background image of a dot: */
35.    background:url(img/dot.png) no-repeat center center;
36.}
37.  
38..clear{
39.    /* Old-school clear fix hack to clear the floats: */
40.    clear:both;
41.}
42.  
43.#main{
44.    margin:0 auto;
45.    position:relative;
46.    width:900px;
47.}

In the lines above you can see the rest of the CSS3 rules that are used. There we add rounded corners via the border-radius property (supported by most of the modern browsers) for both the navigation bar and individual buttons at once.

Step 3 – jQuery

After finishing with all the styling, it is time to throw in some JavaScript. The first step is to include the jQuery library to the head section of the document we are working on.

As I mentioned earlier, there are two modes available for the navigation menu. The first one is the default one, which shows a previously defined shape in a smooth animation when you hover your mouse over a navigation button.

The second one allows you to create your own shapes by clicking on the grid. You can later export the shape and insert it as an array in the shapes object. To make jQuery show it, you just need to insert the name of your just-created shape in the class attribute of the navigation link you wish to associate it with.

Now lets see how this works.

script.js – Part 1

01./* Set serviceMode to true to create your own shapes: */
02.var serviceMode=false;
03.  
04.$(document).ready(function(){
05.  
06.    /* This code is executed after the DOM has been completely loaded */
07.  
08.    var str=[];
09.    var perRow = 16;
10.  
11.    /* Generating the dot divs: */
12.    for(var i=0;i<192;i++)
13.    {
14.        str.push(´<div class="dot" id="d-´+i+´" />´);
15.    }
16.  
17.    /* Joining the array into a string and adding it to the inner html of the stage div: */
18.    $(´#stage´).html(str.join(´´));
19.  
20.    /* Using the hover method: */
21.    $(´#navigation li a´).hover(function(e){
22.  
23.        /* serviceDraw is a cut-out version of the draw function, used for editing and composing shapes: */
24.  
25.        if(serviceMode)
26.            serviceDraw($(this).attr(´class´));
27.        else
28.            draw($(this).attr(´class´));
29.    }, function(e){});
30.  
31.    /* Caching the dot divs into a variable for performance: */
32.    dots = $(´.dot´);
33.  
34.    if(serviceMode)
35.    {
36.        /* If we are in service mode, show borders around the dot divs, add the export link, and listen for clicks: */
37.  
38.        dots.css({
39.            border:´1px solid black´,
40.            width:dots.eq(0).width()-2,
41.            height:dots.eq(0).height()-2,
42.            cursor:´pointer´
43.        });
44.  
45.        $(´<div/>´).css({
46.            position:´absolute´,
47.            bottom:-20,
48.            right:0
49.        }).html(´<a href="" onclick="outputString();return false;">[Export Shape]</a>´).appendTo(´#stage´);
50.  
51.        dots.click(function(){
52.            $(this).toggleClass(´active´);
53.        });
54.    }
55.});

In the topmost part of the file is the serviceMode variable. By setting it to true, you can start creating your own shapes. Just don’t forget to set it back to false after you’ve finished, so that your visitors don’t see the grid and the export link. It would be even better if you keep a dedicated service mode version locally and use a different one for your site (this way you can also strip the unnecessary code for the service mode from the production version).

After the DOM has finished loading (on $(document).ready()) we populate the #stage with a grid of 192 divs (16 per row), that will form the pixels of the image.

script.js – Part 2

01.var shapes={
02.    /* Each shape is described by an array of points. You can add your own shapes here, just don´t forget to add a coma after each array, except for the last one */
03.  
04.    house:[22,37,38,39, .... 166,167,168,169],
05.    wrench:[22,23,24,25,26 .... 148,163],
06.    envelope:[34,35,36,37, .... 153,154,155,156],
07.    info:[22,23,38,39, .... 151,166,167,168]
08.}
09.  
10.var stopCounter = 0;
11.var dots;
12.  
13.function draw(shape)
14.{
15.    /* This function draws a shape from the shapes object */
16.  
17.    stopCounter++;
18.    var currentCounter = stopCounter;
19.  
20.    dots.removeClass(´active´).css(´opacity´,0);
21.  
22.    $.each(shapes[shape],function(i,j){
23.  
24.        setTimeout(function(){
25.        /* If a different shape animaton has been started during the showing of the current one, exit the function  */
26.  
27.        if(currentCounter!=stopCounter) return false;
28.  
29.       dots.eq(j).addClass(´active´).fadeTo(´slow´,0.4);
30.  
31.        /* The fade animation is scheduled for 10*i millisecond into the future: */
32.    },10*i);
33.  
34.});
35.}
36.  
37.function serviceDraw(shape)
38.{
39.    /* A cut out version of the draw function, used in service mode */
40.  
41.    dots.removeClass(´active´);
42.  
43.    $.each(shapes[shape],function(i,j){
44.        dots.eq(j).addClass(´active´);
45.    });
46.}
47.  
48.function outputString()
49.{
50.    /* Exports the positions of the active dot divs as a comma-separated string: */
51.  
52.    var str=[];
53.    $(´.dot.active´).each(function(){
54.        str.push(this.id.replace(´d-´,´´));
55.    })
56.  
57.    prompt(´Insert this string as an array in the shapes object´,str.join(´,´));
58.}

In the second part, you can see the shapes object. It contains four default shapes, which are set as class names to the navigation links. You can customize them by loading them in the service mode, or you can remove them completely and add your own.

After this we define the draw, serviceDraw and the outputString function. The latter two are used only in serviceMode and help you create your own shapes. If you do not plan to use the service mode, you can go ahead and remove them (just don’t forget to also remove lines 34-54 from the first part of script.js above).

With this our CSS3 & jQuery navigation menu is complete!

Tags: jquery, menu, navigation,


Halftone Navigation Menu With jQuery & CSS3Bookmark and Share

Comments

  • ccccc ccccc123

    2013-02-21 11:10:22

    Looking on the face of it you wouldn’t think that hitting a golf ball into a hole would be that hard but it takes a great deal of skill to do this. To acquire these skills you first need to know the basic fundamentals.

    The basics are to hit the ball with a golf club into or as near to the hole as possible. As golf is a competitive sport each time you hit the ball or try to hit the ball is classed as a stroke. The golfer himself keeps a scorecard and www.louisvuittonpursebag.com records the score at the end of every hole. The game of golf is generally played around 18 holes and coach handbags outlet the winner is the person with the least amount of strokes at the end.

    When the players have teed off and had one shot each, the player whose ball is furthest from the hole Coach Factory Online is first to play the next shot and so on, this includes play on the green and the fairway. The player with the least amount of sots on the first hole then goes first on the Louis Vuitton Purses second hole and co on.

    The golf tees are used when first teeing off .Generally most people have at least a couple of drivers, irons and a putter as well as balls, tees and a golf bag. On a par 4 or 5 drivers are generally used when teeing off for greater distance. The golf ball must weigh 1.62 ounces and be round in shape, usually balls are marked with a name and number.

    Golfing etiquette allows players behind you to play through, as in the case where there are two players behind a group of four. The group of four should always be allowed to play through. This allows the smaller group not to be held up. Also you should always make sure that the party in front are not in danger of being hit.

    Make sure you have a good set of golf clubs and wear the right shoes so as not to slip when hitting the ball. Always get your stance right with good posture, get the grip right on the handle. Aim where the ball is going to go, keep your head still and take a full swing always trying to follow through. Keep practicing and try to get a little further each time and try not to tense up.

    Looking on the face of it you wouldn’t think that hitting a golf ball into a hole would be that hard but it takes a great deal of skill to do this. To acquire these skills you first need to know the basic fundamentals.

    The basics are to hit the ball with a golf club into or as near to the hole as possible. As golf is a competitive sport each time you hit the ball or try to hit the ball is classed as a stroke. The golfer himself keeps a scorecard and records the score at the end of every hole. The game of coach bags outlet golf is generally played around 18 holes and the winner is coach outlet store online the person with the least amount of strokes at the end.

    When the players have teed off and had one shot each, the player whose ball is furthest from the hole is first to play the next shot and so on, this includes play on the louis vuitton outlet online green and the fairway. The player with the least amount of sots on the first hole then goes first on the second hole and co on.

    The golf tees are used when first teeing off .Generally most people have at least a couple of drivers, irons and a putter as well coach factory outlet online as balls, tees and a golf bag. On a par 4 or 5 drivers are generally used coach outlet when teeing off for greater distance. coach purses outlet The golf ball must weigh 1.62 ounces and be round in shape, usually balls are marked with a name and number.

    Golfing etiquette allows players behind you to play through, as in the case where there are two players behind a group of four. The group of four should always be allowed to play through. This allows the smaller group not to be held up. Also you coach outlet online should always make sure that the party in front are not in danger of being hit.

    Make sure you have a good set of golf clubs and wear the right shoes so as not to slip when hitting the ball. Always get your stance right with good posture, get the grip right on the handle. Aim where the coach outlet online ball is going to go, keep your head still and take a full swing always trying to follow through. Keep practicing and try to get a little further each time and try not to tense up.

  • lancelsacs lancelsacs

    2013-01-16 08:26:56

    sac lancel premier flirt pas cher

    Avec cette pensée, vous pourriez être en mesure de faire votre propre achat beaucoup plus facile ainsi que pratique. Sacs Lancel soldes sont créés idéal pour profiter de toutes les dames, par le biais de diverses préférences, des vogues divers et différents ère. En conséquence sont très reconnue de toutes les catégories de femmes. Le tissu utilisé pour la production lancel solde pas cher comprend un excellent effet sur le niveau et l'élégance de la bourse. Sac Lancel faire usage de fournitures pouvant être fournis d'une grande brillance ainsi que beaucoup apparaissent. Add-ons tels que des sac Lancel premier flirt pas cher avec revêtement intérieur, vidéos portefeuilles, fermoir, congélateur, touches de commande et ainsi de suite; tendent à être choisis avec soin et chaque article doit combiner en utilisant les matériaux de la bourse. Unique sac lancel soldes en cuir à base peut être la caractéristique de ces bourses. Pores jambes et la peau ainsi que des pores et la peau de kangourou sont utilisés en add-on de qualité supérieure à base de cuir. prix sac Lancel sont faciles à reconnaître grâce à leur forme unique. Ils ont un aspect massif et ont des courbes fermes et ont tendance à être en mesure de se tenir by Lancel. Cela vient en partie de la conception ainsi que de la matière difficile, ils sont fabriqués à partir. Donc, si vous êtes la recherche d'un sac qui n'est pas de disquette, solde sac lancel bon marché sera le plus grand pari. À l'ère d'aujourd'hui, sacs Lancel sont devenus de renom et compter dans de nombreux pays dans le monde. Originaire de France, le créateur "sacs Lancel" a une large base de clientèle. La société sait que les femmes doivent être de haute qualité, et cela peut être exactement ce que leur objectif est.

    http://www.lancel-fr.com/

  • cc xu

    2012-12-23 06:16:33
    XTT-日本でのNO.1人気あるダウンジャケットブランド----モンクレール!冬の日本、一番はやってるクリスマスプレゼントはもちろんモンクレール ダウンです。モンクレール アウトレットの店はさまざまなデザインがあり、値段安いし質も保証あります。さらに今、Moncler アウトレットの店は運賃なしです!クレジットカ—ドで注文したら、十日内には注文した商品は必ず届けます。こんなに安くて便利なショッピング、迷わず買いましょう!
    Louis Vuitton Bags is the history of France's most outstanding leather,in Paris in 1854 opened the first suitcase louis vuitton sale shop name in its own brand.Over the past century has been to advocate refined,quality,comfortable "travel philosophy",starting as a design basis.louis vuitton outlet the name has now spread throughout Europe,became a symbol of the finest travel products.louis vuitton bags outlet store's goods sold to all over the world,quality is guaranteed,and the audience free postage.If you do not want a good Christmas gift,then hurry to the louis vuitton bags on sale store to order it.
    Moncler Outlet enduring mid-renovation and refurbishment,the set dressing style people prefer leisure,moncler jackets will always be the best choice.Design without too pompous,or to totally practical concise styleattractive,neat concise leisure wind consumers can not miss the moncler.In the cold winter,if you do not have a favorite down jacket,moncler outlet store will certainly be your favorite style.
    Are you ready to send what gift in this Christmas?Maybe we can give you some advice.louis vuitton outlet are amazing shopping site in this world,because through it,you can bought the louis vuitton bags in an incredible price,maybe a new way to get Louis Vuitton Handbag,that is louis vuitton online store,as I understand they take the bag from Louis vuitton factory,no tax,no house rent,no compete,these make the price lower then louis vuitton shop,so why not shop the louis vuitton online,amazing Louis Vuitton handbag are belong to you.
    If you are worried for Christmas gift,hermes bags may be a good choice,as the world’s most expensive brand,if you have one, that must stand that you are a good station person in your country, Hermes is famous of it’s hermes handbags,as the hermes handbag’s high qulity and best design, maybe the price is the best in the world.Two series of hermes is popular,that is hermes kelly bags,and hermes birkin bags,this two series make Hermes more popular, so visit our site to get your love.
    What should you send gift in christmas?hermes handbags is waiting for you.Maybe Hermes Handbags is very expensive,but you will be interisted in our replica hermes handbags,we have hermes birkin bags,Hermes Kelly Bags and so on,all of them is quality assured and beautiful,so buy hermes bags on our site,amazing surprise is waiting for you.
  • cainiao198806 cainiao198806

    2012-12-17 10:22:16
    Xiaoping is a Xiushui County, Jiangxi coach handbags coach handbags new 2012 coach factory store louis vuitton outlet Province, whose parents work in Shanghai. Hui'an county business grandparents September of this coach purses real louis vuitton bags coach factory handbag outlet store coach outlet stores year, the 5-year-old Madeleine. Brought Hui'an and nursery residence near East relations coach purses outlet louis vuitton outlet louis vuitton bags coach purse outlet community Shan Fu Kindergarten small classes, usually by Grandma Ms. Yang Shuttle, noon boarding in kindergarten. December 14, 2011, at 3 pm, Ms. Yang received a kindergarten teacher the phone asking Xiaoping why I did not go to louis vuitton coach store online coach handbag outlet sale louis vuitton school. Ms. Yang surprised in the morning, her husband Mr. Lu Xiaoping sent to kindergarten. The teacher subsequently informed, fast 11:00 in the morning, the nursery school, a 40-year-old age, claiming Madeleine "Auntie" Xiaoping picked up. The women to take a bottle of drinks to the Madeleine. Teacher awareness of the coach outlet mall coach handbags coach outlet store online coach factory outlet store women asked Xiaoping, Xiaoping, nodded his head, after the women led away, and after that has not been normalized.
  • af jj

    2012-11-03 03:00:29
    ZBY-

    Christmas is coming!coach outlet is also coming this world now!Coach bags,most famous brand in usa,also the world,why are coach spread so wide,that is because cheap with fashion,the reason why is so cheap because coach always have coach outlet online,we are the online store of coach bags,and they take their product all is from coach factory outlet,no tax no room rent is the advance of coach outlet online store,so come and shopping us now,beautiful bag are waitting for you.
    Are you ready to send what gift in this Christmas?Maybe we can give you some advice.louis vuitton outlet are amazing shopping site in this world,because through it,you can bought the louis vuitton bags in an incredible price,maybe a new way to get Louis Vuitton Handbag,that is louis vuitton online store,as I understand they take the bag from Louis vuitton factory,no tax,no house rent,no compete,these make the price lower then louis vuitton shop,so why not shop the louis vuitton online,amazing Louis Vuitton handbag are belong to you.
    If you want to buy coach for a christmas gift,you can go to our store online.coach outlet is cheapest mall to bought coach bags.as a famous brand in the world,have discount is a incredible thing.Find online store is a new way to get Coach Bags,coach outlet online obviously is a perfect way to get it,in this winter are you really ready to be a fashion women,usa coach outlet will help you,so join us now!coach outlet store online wating for you comeing!
    If you are worried for Christmas gift,hermes bags may be a good choice,as the world’s most expensive brand,if you have one, that must stand that you are a good station person in your country, Hermes is famous of it’s hermes handbags,as the hermes handbag’s high qulity and best design, maybe the price is the best in the world.Two series of hermes is popular,that is hermes kelly bags,and hermes birkin bags,this two series make Hermes more popular, so visit our site to get your love.
    A lot of people want to get a beautiful Coach Bag in christmas.Where can we buy coach bags? A lot of people choose to go to coach outlet store online.All products what sale in coach outlet online are top quality and low price.We promise you to recieve your buy about 5~7days. usa coach outlet directly sell for customers.Do you want to free to buy Coach Bags in your home?Please click coach outlet.
    belstaff jackets is the most popular winter brand in the world,if you don't know,that means you out.belstaff coat is famous of its high-level material and fahisonable design,so that's why so many people choose Belstaff to though the cold winter.Nowaday surffing the internet is the lifestyle of most people,but have you bought things on the internet,I introduce you to try to buy things in the internet,because you can buy belstaff sale on the internet,that way you can get big discount than in reality world,in the brand belstaff trialmaster series is the hottest,this series suit for all kinds of people,whatever you like,whatever you are,you suit it.
    Why buy coach bags from us? Because we have all kinds of Coach products,and these products are high quality and low price.coach factory provide the most perfect service, your order will arrive about 5~7days.Free shipping any order of $99+.Go shopping in people's eyes is women's patent as if .Now a new choice for women is going to coach factory online.If you want to buy Coach Poppy Bag or Coach Wallet, but don't want to go out, coach factory outlet must be your best choice.Are you still hesitate? To click on your mouse to choose your like.
    What should you send gift in christmas? hermes handbags is waiting for you.Maybe Hermes Handbags is very expensive,but you will be interisted in our replica hermes handbags,we have hermes birkin bags,Hermes Kelly Bags and so on,all of them is quality assured and beautiful,so buy hermes bags on our site,amazing surprise is waiting for you.
    On the eve of Christmas comes, coach factory outlet also provide to the most preferential price at this time. coach outlet olinehave many beautiful products, there must be your like.Such Coach bags,Coach sunglass,Coach wallet and so on.Free shipping for any order of $99+.our store will give you a nice present.coach outlet must be Shopping paradise what you want to go.
    What should we buy winter clothes?I think a moncler jackets is necessaery,online moncler is a good way to get a perfect Moncler.Moncleris famous of it amazing qulity and it's consummate manual work,when you ware it,you will feel warm,whatere how cold the winter is,Moncler can take care of your body.Our online store afford latest moncler coat,so in the cold winter you can also fashion and attractive,so visit our moncler online shop,it will take you a warm winter.

You write your thoughts

Please login to post comments here from the right corner.

your add
icon free icon icon set vector icon free catalog catalog template jquery news ticker widget tools tutorial php slider video youtube effects menu thumbnail forms facebook zoom image combo multiselect modal polaroid gallery expand code feedback contact navigation slider tagcloud Skateboard psd templates files badges subscribe panel login temlate file free office holland free template tabs prototype css scriptaculous opacity moo autocomplete wordpress themes design theme button images photoshop fonts font nav pdf logo style high javascript pretty photo jqery lightbox Themes Blog popular blog desing joomla xhtml brushes hair footer admin mootols slide show blackbox new download class first plugin upload browse Page effect modalbox web application urlitooltips sliding boxes captions flatchat chat ajax messaging browser hoverlightbox CSS Dev General Javascript PHP SQL search avatar vector Drupal Joomla Oscommerce javaScript phototype manager ajaxplorer flash xml rotator bookmarking pageflip slideshow poll text component script mediaplayer imagegallery pictograms car poster player mp3 radio onlineradio navigations drop-down collection brush tree textures paper pop-up bumpbox web2.0 iphone film frame twitter page fan mail delete dynamic calender form handbook city social paint timeline clock connect bar sharing accordion quotes ticker photo-effects background 3D media player graphic rss leaf green glossy bubble icon comic clean cool web 2.0 png actionscript ietter rotating Menu animated textured site masking pasword app layer sponge bob popup bubble tooltips horizontal prototip tooltip pack charachters comics blog action icon.psd flavour navi tango gradients istanbul mixed css3 sleek animations program html5 website Layer styles ultimate candy Media icons dropdown snow icon innerfade hover sub tag