We available for hire! — Need help with a web or mobile project?
From yensdesign we develop technology projects based on web apps, mobile apps, consulting and databases. We are young and hard workers, passionate about innovation and focused in new technologies.If you want to ask for a budget, we hare available for hire!.
Create a professional interface for your web applications using jQuery
October 21st, 2008I am very excited to see that a lot of people are linking our tutorials and this the best way to get the motivation to continue writing more and more tutorials. So thanks all for the comments, referrals and for visit yensdesign.com daily
In this tut we will create a professional interface for your web applications using the killer javascript library jQuery, as we used to create the stunning and smooth popup in jQuery.
As always here you have a demo of the final result:
Tested in: Firefox, Internet Explorer 6 & 7, Opera (old and 9.52) , Safari & Chrome (file menu doesn’t works well).
Let’s begin the tutorial guys!
What will We need?
As in other jQuery tutorials We only need these ingredients for our professional interface for our web applications:
- HTML
- CSS
- jQuery Library
- Desire to learn
Step 1: Explaining the layout
The core of this tutorial is the building of the layout. We will build a liquid layout using a simple CSS script for all the process and javascript (in our case with jQuery) to help us to resize the height of our layout when the user resizes the browser window. For people that does’nt know what liquid layout is, here you have a little definition extracted webdesign.com:
Liquid layout are layouts that are based on percentages of the current browser window’s size. They flex with the size of the window, even if the current viewer changes their browser size as they’re viewing the site. Liquid width layouts allow a very efficient use of the space provided by any given Web browser window or screen resolution.
They are often preferred by designers who have a lot of information to get across in as little space as possible, as they remain consistent in size and relative page weights regardless of who is viewing the page.
The preview image that We have seen before, allow us to imagine the schema of the layout, but if you cann’t see it, here you have a schema:
Step 2: Building the layout
So We will have 3 main divisions called: menu, lateralPanel & mainContent and each main division gots other childs divisions:
[sourcecode='html']
New Document Open Save as... Refresh
Print...Favourites
- dmsconsulting.es
- yensdesign.com
- plusmusica.com
- cokidoo.com
- plusdeporte.com
- google.com
General
- delicious.com
- visualizeus.com
- psdtuts.com
[/sourcecode]
- The first main division menu will contains the different sections and subsections.
- The second main division mainContent will have a iframe that will load other webpages in our lateral panel.
- The third main division lateralPanel will have different sections with unordered lists of websites to load in the iframe.
- An additional division called lateralClick to toggle on/off the lateral panel.
Note: In this tutorial We will test the interface with an iframe to see how overflow works but you can delete the iframe and add your custom content in the mainContent division, feel free to experiment!
Step 3: Adding style with CSS
Unlike other tutorials, We won’t use CSS to create the menu interaction, jQuery will be used instead of it, but We will add the main beauty of the example & setup the liquid width of the layout with CSS (the height will be done with jQuery too):
[sourcecode='CSS'] /***************** RESET CSS ***************/ html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td { border:0pt none; font-family:inherit; font-size:100%; font-style:inherit; font-weight:inherit; margin:0pt; padding:0pt; vertical-align:baseline; } html{ height:100%; } body { background:white none repeat scroll 0%; font-size: 12px; font-family:Arial,sans-serif; margin:0pt; height:100%; } table { border-collapse:separate; border-spacing:0pt; } caption, th, td { font-weight:normal; text-align:left; } blockquote:before, blockquote:after, q:before, q:after { content:""; } blockquote, q { quotes:"" ""; } .clear { clear:both; } /*************************************************/ /************* MENU ************/ #menu{ background:transparent url(images/menu_bg.gif) repeat-x scroll left top; display:block; font-size:12px; margin:0pt auto; position:relative; font-family: Trebuchet MS, Arial, Sans-Serif; color:#fff; height:24px; } #menu ul{ list-style-type:none; margin:0pt; padding:0pt; width:auto; } #menu li{ cursor:default; list-style-type:none; display:block; float:left; line-height:24px; margin:0; padding: 0 12px 0 12px; } #fileContainer{ position:absolute; top:24px; left:0px; background:#ecf3fd; border:1px solid #c0dbff; display:none; z-index:1; cursor:default; } #fileContainer ul{ margin:0pt; padding:0pt; width:auto; list-style-position:inside; } #fileContainer li{ list-style-type:none; line-height:24px; margin:0; padding: 0 12px 0 5px; text-align:left; border-bottom:1px solid #e5effc; color:#0079b8; } #fileContainer li .img{ margin:4px 8px 4px 0px; float:left; } #fileContainer li .text{ float:left; } #fileContainer li:hover{ background:#e1ecfb; } #toolsContainer{ position:absolute; top:24px; left:43px; background:#ecf3fd; border:1px solid #c0dbff; display:none; z-index:1; cursor:default; } #toolsContainer ul{ margin:0pt; padding:0pt; width:auto; list-style-position:inside; } #toolsContainer li{ list-style-type:none; line-height:24px; margin:0; padding: 0 12px 0 5px; text-align:left; border-bottom:1px solid #e5effc; clear:both; color:#0079b8; } #toolsContainer li .img{ margin:4px 8px 4px 0px; float:left; } #toolsContainer li .text{ float:left; } #toolsContainer li:hover{ background:#e1ecfb; } #helpContainer{ position:absolute; top:24px; left:95px; background:#ecf3fd; border:1px solid #c0dbff; display:none; z-index:1; cursor:default; } #helpContainer ul{ margin:0pt; padding:0pt; width:auto; list-style-position:inside; } #helpContainer li{ list-style-type:none; line-height:24px; margin:0; padding: 0 12px 0 5px; text-align:left; border-bottom:1px solid #e5effc; clear:both; color:#0079b8; } #helpContainer li .img{ margin:4px 8px 4px 0px; float:left; } #helpContainer li .text{ float:left; } #helpContainer li:hover{ background:#e1ecfb; } #helpContainer li a{ text-decoration:none; cursor:default; } /************* /MENU ************/ /************* MAIN CONTENT ************/ #mainContent{ overflow:auto; } /************* /MAIN CONTENT ************/ /************* LATERALPANEL ************/ #lateralPanel{ width:16%; height:100%; float:right; display:block; margin:0; padding:0; background:#ecf3fd; border-bottom:0px solid #6BABFF; overflow:auto; font-family:Tahoma, arial, verdana, sans-serif; cursor:default; } #lateralPanel ul li{ list-style-type:none; background:transparent url(images/rss.gif) no-repeat scroll 6px top; list-style-position:inside; color:#0079b8; cursor:pointer; padding:5px 10px 5px 30px; font-size:11px; margin-bottom:1px; } #lateralPanel ul li:hover{ background:#d6e8ff url(images/rss.gif) no-repeat scroll 6px top; color:#0099e8; } #lateralPanel ul li.active{ background:#d6e8ff url(images/rss.gif) no-repeat scroll 6px top; color:#0099e8; } #lateralPanel .section{ background: transparent url(images/bgSection.gif); border-bottom:1px solid #9ac3fa; border-top:1px solid #9ac3fa; border:1px 0 1px 0 solid #9ac3fa; height:30px; line-height:30px; vertical-align:middle; color:#fff; text-align:center; font-size:11px; font-weight:700; cursor:pointer; } #lateralPanel .section:hover{ border-color:#6babff; } #lateralClick{ width:10px; height:100%; background:#e5ecf9; float:right; background: transparent url(images/lateralClick_bg.gif); border:1px solid #8fbffe; border-top:0; border-bottom:0; cursor:pointer; text-align:center; } #lateralClick:hover{ cursor:pointer; background: transparent url(images/lateralClick_bg_hover.gif); border-color:#6babff; } #lateralClick #lateralClickImg{ position:relative; top:50%; } /************* /LATERALPANEL ************/ [/sourcecode]
So now with all this things done, we have our layout with-liquid (but not height), by default our mainContent width will be 84% & lateralPanel width will be 16% so if We resize the browser’s window the layout will be adapted in correct % for each division.
The trick to have a liquid layout is use percentages in width & height, but remember that you must set up the html & body elements with height & width at 100% or the their child divisions.
Step 4: Adding magic and interaction with jQuery
As always We will use jQuery to provide interactivity to our professional interface. If you saw the working demo we got some interesting events:
- Setup the height-liquid part of our layout.
- Lateral panel toggle (show/hide) for provide more space to the content division and hide the panel.
- Toggle sections (for websites lists) on/off.
- Top menu with multiple options.
- Change the src value of the iframe by clicking on different websites from the lists of the lateral panel.
We will need some global variables to control the status of some controls:
[sourcecode='JAVASCRIPT'] //global vars var file_status = 0; var tools_status = 0; var help_status = 0; var lateralPanel_status = 1; [/sourcecode]
That variables will help us to know if we must show/hide some elements at the menu or the lateral panel. As always 1 means ON, 0 means OFF. So at the begining, We will hide all elements from top menu, but we will show the lateral panel with website lists.
Now we have the global vars to control the status of our controls, let’s create the functions to show/hide them:
[sourcecode='JAVASCRIPT'] //FUNCTIONS //TOP MENU function fileOn(){ $("#file").css("background","url(images/menu_li_bg.gif)"); } function fileOff(){ $("#file").css("background-image","none"); } function fileHide(){ fileOff(); $("#fileContainer").css("display","none"); file_status = 0; } function fileShow(){ fileOn(); $("#fileContainer").css("display","block"); file_status = 1; } function toolsOn(){ $("#tools").css("background","url(images/menu_li_bg.gif)"); } function toolsOff(){ $("#tools").css("background-image","none"); } function toolsShow(){ toolsOn(); $("#toolsContainer").css("display","block"); tools_status = 1; } function toolsHide(){ toolsOff(); $("#toolsContainer").css("display","none"); tools_status = 0; } function helpOn(){ $("#help").css("background","url(images/menu_li_bg.gif)"); } function helpOff(){ $("#help").css("background-image","none"); } function ayudaShow(){ helpOn(); $("#helpContainer").css("display","block"); help_status = 1; } function helpHide(){ helpOff(); $("#helpContainer").css("display","none"); help_status = 0; } //LATERAL PANEL function lateralPanelShow(){ $("#lateralClickImg").attr("src","images/toggleRight.gif"); $("#lateralPanel").show(); lateralPanel_status = 1; } function lateralPanelHide(){ $("#lateralClickImg").attr("src","images/toggleLeft.gif"); $("#lateralPanel").hide(); lateralPanel_status = 0; } [/sourcecode]
Note: Some people prefers to create the top menu using only CSS, and it’s a great solution but We are trying to learn more about javascript with jQuery.
After all, the only thing We need to do is configure events that call for different functions to show or hide the controls, so let’s move out guys!
Before We start to add the events I remember you that you must to put all jQuery code in the ready event:
[sourcecode='JAVASCRIPT'] $(document).ready(function(){ //here goes the code for the interactions (events) }); [/sourcecode]
Let’s start with the configuration for our height-liquid layout:
[sourcecode='JAVASCRIPT'] /********** CONFIGURE PATTERN ************/ var windowHeight = document.documentElement.clientHeight; var menuHeight = document.getElementById("menu").clientHeight; if(navigator.appName == "Microsoft Internet Explorer"){ $("body").css("max-height",windowHeight-menuHeight); $("#lateralClick").css("height",windowHeight-menuHeight); $("#lateralPanel").css("height",windowHeight-menuHeight); $("#mainContent").css("height",windowHeight-menuHeight); } else{ $("body").css("max-height",windowHeight-menuHeight); $("#lateralClick").css("height",windowHeight-menuHeight); $("#lateralPanel").css("height",windowHeight-menuHeight); $("#mainContent").css("height",windowHeight-menuHeight); } //for resize of the window, recalculate the max-height available window.onresize = function(){ windowHeight = document.documentElement.clientHeight; menuHeight = document.getElementById("menu").clientHeight; $("body").css("max-height",windowHeight-menuHeight); $("#lateralClick").css("height",windowHeight-menuHeight); $("#lateralPanel").css("height",windowHeight-menuHeight); $("#mainContent").css("height",windowHeight-menuHeight); }; [/sourcecode]
Isn’t easy? We calculate the available space at the window at the begining and configure the resize event to recalculate it when the size of the window changes.
So now, We put the code for control events. Don’t be afraid guys, it’s long but very very easy :
[sourcecode='JAVASCRIPT'] /********** TOP MENU ************/ //CLICK FILE MENU $("#file").click(function(){ //HIDE OTHERS //tools toolsHide(); //help helpHide(); //SHOW if(file_status == 0){ //SHOW FILE SUBMENU fileShow(); } //HIDE else{ //HIDE FILE SUBMENU fileHide(); } }); //CLICK TOOLS MENU $("#tools").click(function(){ //HIDE OTHERS //file fileHide(); //help helpHide(); if(tools_status == 0){ //SHOW TOOLS SUBMENU toolsShow(); } else{ //HIDE TOOLS SUBMENU toolsHide(); } }); //CLICK HELP MENU $("#help").click(function(){ //HIDE OTHERS //file fileHide(); //tools toolsHide(); if(help_status == 0){ //SHOW HELP SUBMENU ayudaShow(); } else{ //HIDE HELP SUBMENU helpHide(); } }); //CLICK REFRESH $("#recargar").click(function(){ //REFRESH WEB location.href=""; }); //HOVER FILE MENU $("#file").mouseover(function(){ fileOn(); toolsOff(); helpOff(); if(tools_status == 1 || help_status == 1){ fileShow(); helpHide(); toolsHide(); } }); //HOVER TOOLS MENU $("#tools").mouseover(function(){ toolsOn(); fileOff(); helpOff(); if(file_status == 1 || help_status == 1){ fileHide(); helpHide(); toolsShow(); } }); //HOVER HELP MENU $("#help").mouseover(function(){ helpOn(); fileOff(); toolsOff(); if(file_status == 1 || tools_status == 1){ fileHide(); toolsHide(); ayudaShow(); } }); //MOUSE OUT FILE MENU $("#file").mouseout(function(){ if(file_status == 0){ fileOff(); } }); //MOUSE OUT TOOLS MENU $("#tools").mouseout(function(){ if(tools_status == 0){ toolsOff(); } }); //MOUSE OUT HELP MENU $("#help").mouseout(function(){ if(help_status == 0){ helpOff(); } }); //CLICK NEW (file submenu) $("#new").click(function(){ alert("selected: new"); }); //CLICK OPEN (file submenu) $("#open").click(function(){ alert("selected: open"); }); //CLICK SAVE (file submenu) $("#save").click(function(){ alert("selected: save"); }); //CLICK PRINT (tools submenu) $("#print").click(function(){ print(); }); //CLICK BODY $("div:not(#menu)").click(function(){ fileHide(); toolsHide(); helpHide(); }); //PRESS ESCAPE $(document).keyup(function(event){ fileHide(); toolsHide(); helpHide(); }); /********** LATERAL PANEL ************/ //CLICK LATERALCLICK $("#lateralClick").click(function(){ if(lateralPanel_status == 0){ //MOSTRAMOS LATERALPANEL lateralPanelShow(); } else{ //OCULTAMOS LATERALPANEL lateralPanelHide(); } }); //CLICK SECTION TITLE (toggle) $(".section").click(function(){ $("#" + $(this).attr("id") + " + ul").slideToggle("slow"); }); //CLICK SITE TO CHANGE SRC PROPERTY OF THE IFRAME $("#lateralPanel li").click(function(){ $("#iframe").attr("src","http://"+$(this).text()); //Thanks Shawn user from jquery google groups for the tip! (old code was a little bit complex than his solution ) $("#lateralPanel li").removeClass("active"); $(this).addClass("active"); }); [/sourcecode]
Step 5: Triying our professional finished interface!
And that’s all guys, I hope this tutorial helps you. You can try the tutorial online here to see how It is working and download here all sources.
If you see bugs, bad english, got questions or something tell me by using comments,
Looking for classy chokers for a night party? Search no more because LusterForever.com has it all for you.
See you next time guys!
Enjoy this post?
Your vote will help us to grow this website and write more entries like this one :)
We available for hire! — Need help with a web or mobile project?
From yensdesign we develop technology projects based on web apps, mobile apps, consulting and databases. We are young and hard workers, passionate about innovation and focused in new technologies. We try to help you, sharing our knowledge acquired on worked projects, while helping the community and showing our capabilities.If you want to ask for a budget, we hare available for hire! Don't doubt in get in touch with us!.
Create a professional interface for your web applications using jQuery…
[...]In this tut we will create a professional interface for your web applications using the killer javascript library jQuery, as we used to create the stunning and smooth popup in jQuery.[...]…
This is just an incredible tutorial! Great work!
Create a professional interface for your web applications using jQuery…
The core of this tutorial is the building of the layout. We will build a liquid layout using a simple CSS script for all the process and javascript (in our case with jQuery) to help us to resize the height of our layout when the user resizes the browse…
Great tutorial! Thanks for this one.
Waiting for more!
Ey thanks Dominic nice to see that it’s useful for you
[...] Adrian Mato Gondelle shows how to Create a professional interface for your web applications using jQuery [...]
Nice technique and tutorial! – I didn’t know you could do this sort of menu animation without Flash… Thanks
[...] Create a professional interface for your web applications using jQuery [...]
Ey Damir I’m happy to see that you find this tut useful
Javascript allows you to do lots of things without flash
Hi, nice tutorial… as always…
but i want to point out a very disgusting issue with your code.
the point is: why are you mixing languages in variable and function names? most of your code using english, except the ayudaShow method? why is that? do you really think it makes your code nicer or more maintainable? or do you want to move the world to learn spanish?
it is not any thing personal, it is just that i see this behavior far to often… specially along spanish speaking programmers, including me
Ohhh sorry! I translated another code for this tut hehe ^^
Thanks for you comments
[...] Create a professional interface for your web applications using jQuery [...]
[...] Create a professional interface for your web applications using jQuery | yensdesign – Tutorials, Web… [...]
Good tutorial, thank you!
[...] web: http://yensdesign.com/2008/…ations-using-jquery/ Share and Enjoy: These icons link to social bookmarking sites where readers can share and [...]
Create a professional interface for your web applications using jQuery | yensdesign – Tutorials, Web Design and Coding…
[...][...]…
[...] Create a professional interface for your web applications using jQuery | yensdesign – Tutorials, Web… (tags: website ui tutorials jquery css) [...]
[...] Create a professional interface for your web applications using jQuery | yensdesign – Tutorials, Web… In this tut we will create a professional interface for your web applications using the killer javascript library jQuery, as we used to create the stunning and smooth popup in jQuery. (tags: javascript development css webdesign website) [...]
[...] Create a professional interface for your web applications using jQuery [...]
[...] Breves Publicado Noviembre 12, 2008 Internet * KDE 4.2 es prometedor * Hacer que las tarjetas wifi Atheros AR5007EG o AR242x funcionen en Ubuntu 8.10 * Burn-E, nuevo corto de Pixar * Chrome en Linux avanza positivamente * pequeña gran calculadora en un mundo virtual * Progex, un Ubuntu muy completo * Pekwm themes * La antigua roma y el coliseo en Google Earth * Y si Matrix se ejecutara en Windows… * Jaunty Jackalope Mockup * Crea un interface profesional con JQuery [...]
greats tutorial.
Super article. Can you compress the source code in .tar(.tar.bz, .tar.bz2) format for linux users? Thanks.
Ey Denis! Do you want .zip format? or only .tar?
Thanks for posting!
[...] Create a professional interface for your web applications using jQuery [...]
Great tutorial
Really good job
Thanks lots
Thanks Eric
That’s just what I’ve been looking for! I’m developing a web application and this tutorial gave me lots of ideas for it! Thanks!
Ey Alex that’s nice! Good luck and see you in next tutorials
very Great tutorial
many thanks
Awesome Tutorial!!
you are awesome!
[...] View Tutorial No Comment var addthis_pub=”izwan00″; BOOKMARK This entry was posted on Monday, June 8th, 2009 at 3:55 am and is filed under Javascript Tutorials. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site. [...]
how can make the src of iframe the same even if i press f5 to refresh the page
Great Tutorial. Many Thanks.
Is there a possibility to use Custom Text on the right menu and link it to URL’s? Please help. I am trying to use this in my project.
hi yens,
great work, it is superb.