permalink

112

FormBox – A jQuery & CSS3 Drop-Down Menu With Integrated Forms

Read Later submit to reddit

 

Hey guys. Today I’d like to share something new with you – I call it jQuery FormBox. When designing the layout for a website there’s one thing that we as designers are always conscious of – making things easier for users. No matter what it is your site offers, you’re still going to need to balance the interface in a way that keeps it very easy for users to find and perform core site functions around your site or service, ideally without having to load up a completely different page.

Some of these common functions are logging in, registering or even resetting a password, yet quite often in many cases we still provide users the same old experience – a separate page for logging in, another for signing-up and yet again another if you’ve forgotten what your login details were. Today I would like to present a project that tries to streamline this experience – FormBox.

 

 

 

 

Over the years one aspect of site design which has remained quite consistent is the concept of persistent navigation in the header.For example, if you look at websites such as Amazon.com or Facebook, you’ll notice that the design teams behind giants these tried their best to pack in access to many different areas of their sites through the use of drop-down menus near the top of the page.

When employed correctly, drop-down menus can be a very powerful user interface tool and they were the starting point for how I conceived FormBox. Recently, websites such as Twitter.com popularized the concept of tucking away a login box that popped out when you clicked a single link but what if we were to take these two concepts and integrate them? Drop-down menus and forms that only appear when you need them.

What Is FormBox?.

FormBox is a jQuery and CSS3 powered navigation menu that supports integrated forms. The version presented today features a login form, sign-up form, password reset and even a contact form, all of which are only dropped down when a user hovers over their corresponding menu elements. In technical terms, FormBox works much the way like a tabbed menu does, allowing you to switch between multiple panels of HTML content (forms) which only appear when the user has indicated an interest or need to use them.

This streamlined interface removes the requirement for dedicated registration, login and other types of pages which can instead be easily made available from any page the user is already on, saving them time and simplifying the process in one go. At under 2.5KB uncompressed (including support for graphical tool-tips), FormBox is also a very lightweight solution.

Why is FormBox Useful?

In addition to streamlining the way users are offered forms, in some cases FormBox can also lower the barrier of entry to some of the features your site may offer when it comes to forms. For example, if your website currently has registration and login features, how many clicks does it currently take for a user to get to those pages?. The average is usually between 1 and 2 for most (and that’s doubled if the user has to login again after signing up). How about how many clicks it takes them to reset their password or even get in touch with you?. With FormBox, there are no clicks. You simply hover over an item such as ‘Login’, ‘Register’ or ‘Contact’ and you’re presented with that form.

If you’re concerned about not being able to give your users sufficient instructions or feedback for form input, FormBox takes care of that too. You’re able to display a very visible graphical tooltip whenever a user hovers over an input field so if they need to know what length or content a password needs to contain, lack of space isn’t an issue. I wanted to stop short of including built-in form validation, but if you’re interested in using FormBox in a project, it’s fairly easy to integrate some of the existing jQuery validation plugins into the code. In my opinion FormBox is an elegant, simple proof of concept of a way we can further improve user experience by trying things outside of the norm.

 

How Do You Create FormBox?

If you’ve ever used an implementation of tabs powered by jQuery (or another JS framework), you’ll find using FormBox quite straight-forward. Each individual form ‘menu’ is actual a tab panel which can be triggered by clicking on a menu link referencing it’s hash ID (eg. #tab2). This approach allows for both standard menu links and form drop-downs to be supported easily.

Let’s first take a look at the HTML required to create FormBox – as you can see we begin by creating a UL/LI list of links and attaching a class of ‘regular’ or ‘dropdown’ to each of these menu items.  Next, we define a FormBox panel which contains our HTML/Form code. For the sake of length I am only including one example of these but if you grab the sources you’ll be able to see each drop-down panel is defined similarly.

HTML



  •  
    Remember Me
     


JavaScript

The jQuery used in FormBox powers the drop-down menus, animation, tool-tips and re-positioning. Below you can find the most important functions used in this demo or alternatively you can pick up the sources to see the code in full.

By default, FormBox works as a hover-based interface. Hovering over a menu item with a drop-down on it displays the menu. You can of course change this behavior by changing tabMenuLinks.hover() into a click() function and defining a separate piece of CSS or jQuery to cover the addition of the active class to your menu links. The below will give you everything you need to get started with either:

$(window).load(function(){
var tabs = $("#tabs");
var tabPanesContainer = $("ul#tabPanes");
var tabPanesAll = tabPanesContainer.find("li").css("position", "absolute");
var tabMenuLinks = $("ul#tabMenu .dropdown");
var regularLinks = $("ul#tabMenu .regular");
var dropDownSpeed = 200;
var dropUpSpeed   = 200;
var menuHeight = '240px';
/*Handle menu links - display the form panel on hover*/
tabMenuLinks.hover(function()
{
    var thisMenuItem = $(this);
    /*get the offset of this item in respect to the page*/
    var thisMargin   = thisMenuItem.offset().left;
    /*get the offset of the navigation bar in respect to the page*/
    var tabsOffset   = tabs.offset().left;
    var thisIndex = thisMenuItem.index();
    thisMargin = Math.floor(thisMargin - tabsOffset);
    /*correct the offset*/
    var thisOffset = thisMargin - 52;
    tabPanesContainer.css('margin-left', thisOffset);
    /*begin animateing the drop down*/
    tabPanesContainer.stop().animate({
        height: menuHeight
    }, dropDownSpeed);
    /*remove the active class from other menu items*/
    tabMenuLinks.removeClass('activeTab');
    /*add the active class to the current menu item*/
    thisMenuItem.addClass('activeTab');
    /*detect and switch to the current form panel*/
    var thisHash = thisMenuItem.find("a").attr('href');
    var tabClicked = tabPanesAll.filter(thisHash);
    tabClicked.appendTo(tabPanesContainer).show();
    return false;
}, function() {
   $(this).stop();
});
/*Close the currently open menu*/
function closeMenu()
{
tabMenuLinks.removeClass('activeTab');
    tabPanesContainer.stop().animate({
        height: '0px'
    }, dropUpSpeed);
}
/*Handle non tab-menu links*/
regularLinks.hover(function()
{
    tabPanesContainer.stop().animate({
        height: '0px'
    });
    tabMenuLinks.removeClass('activeTab');
    $(this).addClass('activeTab');
}, function() {
    $(this).removeClass('activeTab');
});

CSS

My FormBox demo is quite graphical in nature but what we want to focus on is the CSS for the drop-down tab panes and the FormBox menu itself (the div called ‘tabs’). In the complete sources you can find the classes used to enable regular links in the tabbed interface as well as the drop-downs. You can also find the code to the raised CSS3 buttons in this pack.

#tabs {
width:604px;
height:47px;
background-image:url('../images/wooden8.png');
-webkit-box-shadow: 0px 5px 6px rgba(0,0,0,0.8);
-moz-box-shadow: 0px 5px 6px ;
box-shadow: 0px 5px 6px ;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
font-family:Arial;
font-size:14px;
margin:0 auto;
}
ul#tabPanes
{
    margin-left:52px;
    position:relative;
    width:227px;
    overflow: hidden;
    clear:both;
    font-family:Arial;
    list-style-type: none;
    margin-top:-0px;
    position:absolute;
}
ul#tabPanes li
{
    width: 227px;
}
ul#tabPanes li#tab1,li#tab2,li#tab3,li#tab4
{
    height:227px;
    margin-top:-30px;
    margin-left:-3px;
    display:none;
    text-shadow: #ffffff 0px 1px 0px;
     background-color:#C9AA7C;
     -moz-border-radius-bottomright: 5px;
     -moz-border-radius-bottomleft: 5px;
     -webkit-border-bottom-right-radius:5px;
     -webkit-border-bottom-left-radius:5px;
     background-image:url('../images/wood3.jpg');
     background-repeat:no-repeat;
    -webkit-box-shadow: 0px 3px 4px rgba(0,0,0,0.6);
     -moz-box-shadow: 0px 3px 4px ;
     box-shadow: 0px 3px 4px ;
}

 

 

The Tooltips – JavaScript

If you’ve had a chance to watch my jQuery Plugin In Under 5 Minutes screencast, the next piece of code will look a little familiar. This is the jQuery that powers the tooltips found in FormBox. When a user hovers over an input field, the code checks to see if an alt tag has been defined for it. If it has, we append the tooltip to the DOM and then position it relative to the element the user has hovered over. When a user hovers off the element, we simply remove the tooltip from our stack.

An alternative approach to this (which may trim a few milliseconds off the display time) is using a single persistent element for your tooltip object which you can then hide/re-position/populate and show as and when needed. Both techniques use some of the same code code and the below code snippet covers this functionality.

$('input').hover(function()
{
var thisItem = $(this);
var msgTip = thisItem.attr('alt');
if(msgTip.length)
{
  $('body').append('\'+  msgTip +'\');
		var pos = thisItem.offset();
		var width = thisItem.width();
		$("#menuTooltip").css( { "left": (pos.left
+ 115) + "px", "top":pos.top - 90 + "px" } );
		$("#menuTooltip").fadeIn('slow');
}
}, function()
{
  $('div#menuTooltip').remove();
});

 

Demos and Downloads
And that’s it!. If you would like to download the sources to FormBox or check out a demo, please see below for the links. FormBox is compatible with FireFox, Chrome, Safari and Internet Explorer 6.0+.

 

 

Enjoyed this post?, please feel free to share it with your friends and colleages by clicking the retweet button.

 

112 Comments

  1. Nice job Addy. You continue to surprise me with the thoroughness of your tutorials.

    This concept, execution and recipe brings a number of ideas for use in upcoming projects. Thanks again.

  2. Pingback: Начнем копаться! – Херсонский бомжара

  3. Addy, this sample looked great in Chrome and FF 3.6.8, but IE8 the menus were skewed to the right… they were not dropping down left-justified to their respective buttons, meaning I had to diagonal move mouse to get to menu. idea is pretty spiff though! Thanks

  4. Pingback: 160+ Awesome Articles for Web Designers and Developers — tripwire magazine

  5. Pingback: 160+ Awesome Articles for Web Designers and Developers | Prabaharan CS Blog

    • Hey Benas. I've found this works most smoothly in WebKit browsers but I'm sure there are some tweaks that could be made to my code to improve performance :)

  6. Just an opinion – shouldn't a FORM be nested within a form html element? If you're serious with this, there should already be a form tag with ID, name, action attributes, wrapping "form stuff" with a fieldset instead of .text div. You can just give the fieldset block display, if it already is not displayed that way. It's more structural and semantic that way.

    Other than that, it's a nice and useful thing to have at hand. Either way one will have to additionaly style and edit the code, so, browser inconsistency does not matter now.

    • Hey zhille. It should of course include the Form element. I didn\’t include it on purpose in the demo as I didn\’t want lots of people hitting the submit button, but in a real world implementation you would definitely include form anywhere needed.

  7. standalone form pages would still be needed for error-handling (depending) and/or non-js users. Perhaps jquery can be used to grab the form from those other pages and insert them into those dynamic tabby elements when the page loads.

  8. Pingback: infomisa.net» Blog Archive » FormBox: jQuery/CSS3 Drop-Down Menu with Integrated Forms

  9. Pingback: Weekly Design News – Resources, Tutorials and Freebies (N.56) « UKWDS!

  10. Wow! Great tutorial! I think it is an excellent idea to integrate the forms in de drop-down menu but I think it might improve the usability if you keep the forms visible when you are typing in a form field and move your mouse away.

    • Hey Rose,

      Thanks for the comment :) I went through about 8 iterations trying to work out the best way to present the UI and I think that there are a number of ways it could be done in live form – if the form was still visible when the user hovered away I think that the menu would require either a click on the parent/title to close it up (one possible case) or some sort of alternative closing method (eg. an X, although this would look a little weird) to close the form up. The compromise I ended up with is that even if the form gets slid up when you hover away, hovering back over the menu item allows you to easily access the form again (with all your text in place) without needing to re-type in anything.

      Feel free to contribute any other ideas you might have on the implementation as I may update the release at some point :)

      Thanks
      Addy

      • Addy, I love this dropdown solution! I can see a lot of uses for this for a current project and upcoming projects. You did an awesome job, Congrats!

        One question, sometimes when I scroll-over and out, the box stays open and it takes a few back-and-forth hovers to get it to close again. How could I add a click-out to close option?

        Thanks again!

  11. Pingback: Выдвижное всплывающее меню-форма | Мир CSS

  12. Pingback: amazing jquery navigation menu tutorials | ExtraTuts

  13. Pingback: jQuery Uygulamaları (Eylül Ayı) | Mert Arabacıer

  14. Pingback: Drop-Down Menu With Integrated Forms « Jquery Labs

  15. Pingback: 45 jQuery Menu Tutorials Plugins | webdesign14.com

  16. It is greath!

    Right now i have one project and i search for somme theme and inspiration. The client is working in wood industry and the backround of you demo is PERFECT. The menu is, also, best fitting for the project!

    Thanks a loot!

    I salute to You!
    Venus from Capilnas/Romania, not from Milo! :)

  17. Pingback: FormBox – A jQuery & CSS3 Drop-Down Menu With Integrated Forms :DotNetInfos

  18. Pingback: jQuery & CSS3 Drop-Down Menu With Integrated Forms « Ashish Design World

  19. Pingback: 10 Best Dropdown menus using jQuery | Mblog

  20. Pingback: Top 100 Useful And Detailed CSS3 Tutorials And Techniques « qeqnes | Designing. jQuery, Ajax, PHP, MySQL and Templates

  21. Pingback: Beginner’s Guide to CSS3

  22. Pingback: Beginner’s Guide to CSS3 | Ruturaj Pradeep Kohok | Your Web Advisor

  23. Pingback: Beginner’s Guide to CSS3 « Web Design News

  24. Pingback: Shared on FAQPAL.com

  25. Pingback: Beginner’s Guide to CSS3 |

  26. Pingback: Beginner’s Guide to CSS3 | Emre Saraçoğlu's Official Blog

  27. Pingback: Beginner’s Guide to CSS3 « DownGraf – Design weblog for designers

  28. Pingback: FormBox – Drop Down Menus With Forms using jQuery & CSS3 | ChurchCode

  29. Nice tutorial, except for the part where you say "removes the requirement for dedicated registration, login and other types of pages".

    You should ALWAYS have a dedicated page for these tasks. You then enhance the user experience by using something like FormBox to "remove the requirement to be redirected". It is good practice to build a usable site for the javascript-disabled and the seeing impaired.

  30. Pingback: jQuery & CSS3 Drop-Down Menu With Integrated Forms: FormBox | Greepit

Leave a Reply

Required fields are marked *.

*