All in one forum  - Applications | Games | E-Books | Music, Movies & Videos | Mobile Stuff | Live Discussions | Webmaster Stuff | Many More | Community to Hang Out and Stick to
Search Today's Posts Mark Forums Read

Go Back   Home > Tutorial Section > Programming > JavaScript
Reload this Page [Tutorial] How To Create A ‘Mootools Homepage’ Inspired Navigation Effect Using jQuery
Forgot Password? Join Us!
JavaScript Post your JavaScript Related Tutorial Here

Notices
Your link here Your link here Your link here Your link here Your link here

Your Ad Here


Rate This Thread - How To Create A ‘Mootools Homepage’ Inspired Navigation Effect Using jQuery.

Post New Thread Reply
Bookmarks
 
LinkBack Thread Tools Display Modes
Old 06-12-2008, 02:30 PM   #1 (permalink)
 
KoOL's Avatar
 
User Info
Join Date: Oct 2007
Location: In You Mind
Age: 26
Achievements Posts: 10,269
Casino Cash: $1066970

Total Points: 236,720,623,820.53
Donate

Reputation: 90833
KoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond repute


Awards Showcase
Administrator Of the Month Of Jan 
Total Awards: 1
How To Create A ‘Mootools Homepage’ Inspired Navigation Effect Using jQuery

Step 1

Let's begin by writing the necessary HTML to create a simple vertical navigation. For the structure, as you may have guessed, we will use an unordered list <ul> with the ID name "sliding-navigation". Also, we will add some links and give each list item <li> the class name "sliding-element".
I'm also going to add in a title element. This is a useful thing to do as many WordPress blogs for example have title elements in their sidebar navigation (e.g. "Archives"). So it would look something like this:
view plaincopy to clipboardprint?

  1. <ul id="sliding-navigation">
  2. <li class="sliding-element"><h3>Navigation Title</h3></li>
  3. <li class="sliding-element"><a href="#">Link 1</a></li>
  4. <li class="sliding-element"><a href="#">Link 2</a></li>
  5. <li class="sliding-element"><a href="#">Link 3</a></li>
  6. <li class="sliding-element"><a href="#">Link 4</a></li>
  7. <li class="sliding-element"><a href="#">Link 5</a></li>
  8. </ul>

<ul id="sliding-navigation"> <li class="sliding-element"><h3>Navigation Title</h3></li> <li class="sliding-element"><a href="#">Link 1</a></li> <li class="sliding-element"><a href="#">Link 2</a></li> <li class="sliding-element"><a href="#">Link 3</a></li> <li class="sliding-element"><a href="#">Link 4</a></li> <li class="sliding-element"><a href="#">Link 5</a></li> </ul> Step 2

Now, let's create a HTML document where we can put the work we just did. Create a new HTML file and call it demo.html. Then open this file with your favorite text editor and insert the following code: view plaincopy to clipboardprint?

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html>
  4. <head>
  5. <title>Navigation Effect Using jQuery</title>
  6. <link rel="stylesheet" type="text/css" href="styles.css" />
  7. <script type="text/javascript" src="jquery.js"></script>
  8. <script type="text/javascript" src="sliding_effect.js"></script>
  9. </head>
  10. <body>
  11. <div id="navigation-block">
  12. <ul id="sliding-navigation">
  13. <li class="sliding-element"><h3>Navigation Title</h3></li>
  14. <li class="sliding-element"><a href="#">Link 1</a></li>
  15. <li class="sliding-element"><a href="#">Link 2</a></li>
  16. <li class="sliding-element"><a href="#">Link 3</a></li>
  17. <li class="sliding-element"><a href="#">Link 4</a></li>
  18. <li class="sliding-element"><a href="#">Link 5</a></li>
  19. </ul>
  20. </div>
  21. </body>
  22. </html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Navigation Effect Using jQuery</title> <link rel="stylesheet" type="text/css" href="styles.css" /> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="sliding_effect.js"></script> </head> <body> <div id="navigation-block"> <ul id="sliding-navigation"> <li class="sliding-element"><h3>Navigation Title</h3></li> <li class="sliding-element"><a href="#">Link 1</a></li> <li class="sliding-element"><a href="#">Link 2</a></li> <li class="sliding-element"><a href="#">Link 3</a></li> <li class="sliding-element"><a href="#">Link 4</a></li> <li class="sliding-element"><a href="#">Link 5</a></li> </ul> </div> </body> </html> There are a few things to note here:
  1. The !DOCTYPE for our demo.html file is set to XHTML 1.0 Strict. This is not required for the effect to work but I try to get in the habit of using it as much as I can.
  2. You may have notice that the <link> tag is refering to a file called style.css. However, no such file exists. No worries though, that is the next step.
  3. Finally I've wrapped my navigation block into a <div>. We'll make use of this later to position the block on the page.
Step 3

Now that we have our HTML file labelled and working, let's add some styles. Remember that our HTML document is pointing to a CSS file called styles.css. So, let's begin by creating a file called styles.css and saving it in the same directory where our HTML document lives. As we did in the previous step, open this file with your favorite text editor and insert the following code: view plaincopy to clipboardprint?

  1. body
  2. {
  3. margin: 0;
  4. padding: 0;
  5. background: #1d1d1d;
  6. font-family: "Lucida Grande", Verdana, sans-serif;
  7. font-size: 100%;
  8. }
  9. ul#sliding-navigation
  10. {
  11. list-style: none;
  12. font-size: .75em;
  13. margin: 30px 0;
  14. }
  15. ul#sliding-navigation li.sliding-element h3,
  16. ul#sliding-navigation li.sliding-element a
  17. {
  18. display: block;
  19. width: 150px;
  20. padding: 5px 15px;
  21. margin: 0;
  22. margin-bottom: 5px;
  23. }
  24. ul#sliding-navigation li.sliding-element h3
  25. {
  26. color: #fff;
  27. background: #333;
  28. border: 1px solid #1a1a1a;
  29. font-weight: normal;
  30. }
  31. ul#sliding-navigation li.sliding-element a
  32. {
  33. color: #999;
  34. background: #222;
  35. border: 1px solid #1a1a1a;
  36. text-decoration: none;
  37. }
  38. ul#sliding-navigation li.sliding-element a:hover { color: #ffff66; }

body { margin: 0; padding: 0; background: #1d1d1d; font-family: "Lucida Grande", Verdana, sans-serif; font-size: 100%; } ul#sliding-navigation { list-style: none; font-size: .75em; margin: 30px 0; } ul#sliding-navigation li.sliding-element h3, ul#sliding-navigation li.sliding-element a { display: block; width: 150px; padding: 5px 15px; margin: 0; margin-bottom: 5px; } ul#sliding-navigation li.sliding-element h3 { color: #fff; background: #333; border: 1px solid #1a1a1a; font-weight: normal; } ul#sliding-navigation li.sliding-element a { color: #999; background: #222; border: 1px solid #1a1a1a; text-decoration: none; } ul#sliding-navigation li.sliding-element a:hover { color: #ffff66; } Step 4

At this point your demo.html page should be looking something like this:
So, it is finally time to begin using jQuery. But before we can get started we need to do a few of things:
  1. Download the latest version of jQuery.
  2. Create a new file called sliding_effect.js and save it in the same directory as that of your HTML and CSS file.
  3. Lastly, insert the two previous files to your HTML document's <head>.
This is what your HTML file's <head> should look like now: view plaincopy to clipboardprint?

  1. <head>
  2. <title>Navigation Effect Using jQuery</title>
  3. <link rel="stylesheet" type="text/css" href="styles.css" />
  4. <script type="text/javascript" src="jquery.js"></script>
  5. <script type="text/javascript" src="sliding_effect.js"></script>
  6. </head>

<head> <title>Navigation Effect Using jQuery</title> <link rel="stylesheet" type="text/css" href="styles.css" /> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="sliding_effect.js"></script> </head> Step 5

Now, we will create the function that will do all the "heavy" lifting for the sliding effect to work. This function will take five parameters (navigation_id, pad_out, pad_in, time, and multiplier) and use them as follows:
  1. navigation_id: This is the ID name of the navigation, which contains the elements the effect will be applied on.
  2. pad_out: This is the number of pixels to be padded left when one of the links inside the navigation is hovered.
  3. pad_in: This is the number of pixels to be padded left when one of the links inside the navigation is no longer being hovered.
  4. time: This represents the amount of time (in milliseconds) that takes for one of the link elements to slide in and back in to place when the page is loaded.
  5. multiplier: The job of the multiplier is to increase or decrease the amount that takes the a following link element to slide in to the screen. In other words, if the multiplier is 1, all link elements will slide in to the screen in equal time intervals. However, if it is less than 0, the subsequent link elements will slide in faster, and if it is more than 1 the opposite will happen.
So, open your sliding_effect.js file and insert the following code: view plaincopy to clipboardprint?

  1. function slide(navigation_id, pad_out, pad_in, time, multiplier)
  2. {
  3. // creates the target paths
  4. var list_elements = navigation_id + " li.sliding-element";
  5. var link_elements = list_elements + " a";
  6. // initiates the timer used for the sliding animation
  7. var timer = 0;
  8. // creates the slide animation for all list elements
  9. $(list_elements).each(function(i)
  10. {
  11. // margin left = - ([width of element] + [total vertical padding of element])
  12. $(this).css("margin-left","-180px");
  13. // updates timer
  14. timer = (timer*multiplier + time);
  15. $(this).animate({ marginLeft: "0" }, timer);
  16. $(this).animate({ marginLeft: "15px" }, timer);
  17. $(this).animate({ marginLeft: "0" }, timer);
  18. });
  19. // creates the hover-slide effect for all link elements
  20. $(link_elements).each(function(i)
  21. {
  22. $(this).hover(
  23. function()
  24. {
  25. $(this).animate({ paddingLeft: pad_out }, 150);
  26. },
  27. function()
  28. {
  29. $(this).animate({ paddingLeft: pad_in }, 150);
  30. });
  31. });
  32. }

function slide(navigation_id, pad_out, pad_in, time, multiplier) { // creates the target paths var list_elements = navigation_id + " li.sliding-element"; var link_elements = list_elements + " a"; // initiates the timer used for the sliding animation var timer = 0; // creates the slide animation for all list elements $(list_elements).each(function(i) { // margin left = - ([width of element] + [total vertical padding of element]) $(this).css("margin-left","-180px"); // updates timer timer = (timer*multiplier + time); $(this).animate({ marginLeft: "0" }, timer); $(this).animate({ marginLeft: "15px" }, timer); $(this).animate({ marginLeft: "0" }, timer); }); // creates the hover-slide effect for all link elements $(link_elements).each(function(i) { $(this).hover( function() { $(this).animate({ paddingLeft: pad_out }, 150); }, function() { $(this).animate({ paddingLeft: pad_in }, 150); }); }); } Step 6

All we need to do in order to trigger the script is call the function when the page has loaded. There are two place to put the following snippet of code. It can either be written inside the sliding_effect.js file (I chose this option for this tutorial) or called within the HTML using a <script> tag. Either case will use the same code, which is as follows: view plaincopy to clipboardprint?

  1. $(document).ready(function()
  2. {
  3. slide([navigation_id], [pad_out], [pad_in], [time], [multiplier]);
  4. });

$(document).ready(function() { slide([navigation_id], [pad_out], [pad_in], [time], [multiplier]); }); Step 7

Finally we'll add a bit of style to the page to make it look slightly more glamourous. First I've created an image block that looks like this:

The image has a faint gradient, a highlight line, is 190px wide and called "background.jpg". The idea will be to position this to the left of our navigation so that the buttons slide in under it. We'll also add a little heading title to the page. So our HTML becomes:
view plaincopy to clipboardprint?

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html>
  4. <head>
  5. <title>Navigation Effect Using jQuery</title>
  6. <link rel="stylesheet" type="text/css" href="styles.css" />
  7. <script type="text/javascript" src="jquery.js"></script>
  8. <script type="text/javascript" src="sliding_effect.js"></script>
  9. </head>
  10. <body>
  11. <div id="navigation-block">
  12. <img src="background.jpg" id="hide" />
  13. <h2><span>Navigation Effect Using jQuery</span></h2>
  14. <p>By Bedrich Rios</p>
  15. <ul id="sliding-navigation">
  16. <li class="sliding-element"><h3>Navigation Title</h3></li>
  17. <li class="sliding-element"><a href="#">Link 1</a></li>
  18. <li class="sliding-element"><a href="#">Link 2</a></li>
  19. <li class="sliding-element"><a href="#">Link 3</a></li>
  20. <li class="sliding-element"><a href="#">Link 4</a></li>
  21. <li class="sliding-element"><a href="#">Link 5</a></li>
  22. </ul>
  23. </div>
  24. </body>
  25. </html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Navigation Effect Using jQuery</title> <link rel="stylesheet" type="text/css" href="styles.css" /> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="sliding_effect.js"></script> </head> <body> <div id="navigation-block"> <img src="background.jpg" id="hide" /> <h2><span>Navigation Effect Using jQuery</span></h2> <p>By Bedrich Rios</p> <ul id="sliding-navigation"> <li class="sliding-element"><h3>Navigation Title</h3></li> <li class="sliding-element"><a href="#">Link 1</a></li> <li class="sliding-element"><a href="#">Link 2</a></li> <li class="sliding-element"><a href="#">Link 3</a></li> <li class="sliding-element"><a href="#">Link 4</a></li> <li class="sliding-element"><a href="#">Link 5</a></li> </ul> </div> </body> </html> Notice that I've added the image inside the "navigation-block" element and give it an ID called "hide". Also I've added a heading element and subtitle. Now we add a bit of extra CSS to our styles.css file as follows:
view plaincopy to clipboardprint?

  1. h2
  2. {
  3. color: #999;
  4. margin-bottom: 0;
  5. margin-left:13px;
  6. background:url(navigation.jpg) no-repeat;
  7. height:40px;
  8. }
  9. h2 span
  10. {
  11. display: none;
  12. }
  13. p
  14. {
  15. color: #ffff66;
  16. margin-top: .5em;
  17. font-size: .75em;
  18. padding-left:15px;
  19. }
  20. #navigation-block {
  21. position:relative;
  22. top:200px;
  23. left:200px;
  24. }
  25. #hide {
  26. position:absolute;
  27. top:30px;
  28. left:-190px;
  29. }

h2 { color: #999; margin-bottom: 0; margin-left:13px; background:url(navigation.jpg) no-repeat; height:40px; } h2 span { display: none; } p { color: #ffff66; margin-top: .5em; font-size: .75em; padding-left:15px; } #navigation-block { position:relative; top:200px; left:200px; } #hide { position:absolute; top:30px; left:-190px; } So first in the <h2> element, we have set the HTML text to vanish using "display:none" and set a background image of some nicer looking text I prepared earlier.
Also notice that the "navigation-block" element now has a relative position, so that we can move the "hide" image over to the left. This will make the tabs appear from under it.
Lastly to give our tabs a bit of finish I've added a subtle background image that looks like shading like this:
view plaincopy to clipboardprint?

  1. ul#sliding-navigation li.sliding-element h3
  2. {
  3. color: #fff;
  4. background:#333 url(heading_bg.jpg) repeat-y;
  5. font-weight: normal;
  6. }

ul#sliding-navigation li.sliding-element h3 { color: #fff; background:#333 url(heading_bg.jpg) repeat-y; font-weight: normal; } Finished

And we're done!


For Download Links U need to Press Thanks Button
My Goal 2: (Complete 10000)

Please don't PM me For Posts, Request and Not Working Threads. Use Button.
KoOL is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following 3 Users Say Thank You to KoOL For This Useful Post:
barnick (06-28-2008), PaNkAJ (06-12-2008), rajeevaga (07-10-2008)
Click here to Donate to remove the Adverts.
Your Ad Here
Old 06-12-2008, 02:32 PM   #2 (permalink)
 
PaNkAJ's Avatar
 
User Info
Join Date: Jul 2007
Location: In Your Heart
Achievements Posts: 9,418
Casino Cash: $609080

Total Points: 6,071,843.43
Donate

Reputation: 96476
PaNkAJ has a reputation beyond reputePaNkAJ has a reputation beyond reputePaNkAJ has a reputation beyond reputePaNkAJ has a reputation beyond reputePaNkAJ has a reputation beyond reputePaNkAJ has a reputation beyond reputePaNkAJ has a reputation beyond reputePaNkAJ has a reputation beyond reputePaNkAJ has a reputation beyond reputePaNkAJ has a reputation beyond reputePaNkAJ has a reputation beyond repute


Awards Showcase
Administrator Of the Month Of Jan 
Total Awards: 1
Amazing tutorial .... Thanks

Guests Register to see the forum...
Read & Follow the Rules

Click on thanks & take the Link with you....No Spamming with reply

I'm on vacation. W'll be back on 15th Sep
PaNkAJ is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Click here to Donate to remove the Adverts.
Your Ad Here
Old Today, 06:27 PM   #3 (permalink)
 
henry809's Avatar
 
User Info
Join Date: Mar 2008
Achievements Posts: 32
Casino Cash: $3000

Total Points: 940.67
Donate

Reputation: 20
henry809 is on a distinguished road


good i like it
henry809 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply
Click here to Donate to remove the Adverts.
Your Ad Here
Post New Thread Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] Create a Cool Animated Navigation with CSS and jQuery KoOL JavaScript 0 06-12-2008 02:26 PM
[Tutorial] Make a list of web buttons Balvairorks professionally Create a navigation for a website KoOL Adobe Fireworks 0 06-11-2008 04:38 AM
Photoshop Tutorial - Create a Text Reflection Effect PaNkAJ Adobe Photoshop 1 05-04-2008 06:47 AM
Photoshop Tutorial - Create a Kool Matrix Effect PaNkAJ Adobe Photoshop 1 02-16-2008 01:25 AM
Photoshop Tutorial - Create a Fade-In Fade-Out Effect PaNkAJ Adobe Photoshop 0 01-12-2008 09:09 AM



Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles

RapidShare Links PhazeDDL Warez
PhazeDDL Warez