Introduction
Today, I have provided an article showing you how to create a login drop-down with a Twitter-style using jQuery. There are many ways in which a user can log in. A popular method since the birth of Twitter is to have a DropDown form. Today we provide a simple jQuery DropDown login form, it's easy to implement. All you must do is implement and hook it up to your website. First of all, start Visual Studio .NET and make a new ASP.NET web site using Visual Studio 2010.
Now you need to create a web site.
- Go to Visual Studio 2010
- New-> Select a website application
- Click OK
Now add a new page to the website.
- Go to the Solution Explorer
- Right-click on the Project name
- Select add a new item
- Add a new web page and provide it a name
- Click OK
Now add a CSS folder to the application that contains some style code. Put this code in the style.css file.
Now add a login.js file under the scripts folder in the application that contains some JavaScript code.
- $(function() {
- var button = $('#loginButton');
- var box = $('#loginBox');
- var form = $('#loginForm');
- button.removeAttr('href');
- button.mouseup(function(login) {
- box.toggle();
- button.toggleClass('active');
- });
- form.mouseup(function() {
- return false;
- });
- $(this).mouseup(function(login) {
- if(!($(login.target).parent('#loginButton').length > 0)) {
- button.removeClass('active');
- box.hide();
- }
- });
- });
Now add the references for the CSS file and JavaScript files in the head section of the .aspx code.
- <link href="css/style.css" rel="stylesheet" type="text/css" />
- <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
- <script src="Scripts/login.js" type="text/javascript"></script>
The .aspx code will be as shown below.
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TwitterLogin.aspx.cs" Inherits="TwitterLogin" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <link href="css/style.css" rel="stylesheet" type="text/css" />
- <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
- <script src="Scripts/login.js" type="text/javascript"></script>
- <meta charset="utf8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
- <title>jQuery Dropdown Login Freebie | The Finished Box</title>
-
- </head>
- <body>
- <div id="bar">
- <div id="container">
- <!-- Login Starts Here -->
- <div id="loginContainer">
- <a href="#" id="loginButton"><span>Login</span><em></em></a>
- <div style="clear:both"></div>
- <div id="loginBox">
- <form id="loginForm">
- <fieldset id="body">
- <fieldset>
- <label for="email">Email Address</label>
- <input type="text" name="email" id="email" />
- </fieldset>
- <fieldset>
- <label for="password">Password</label>
- <input type="password" name="password" id="password" />
- </fieldset>
- <input type="submit" id="login" value="Sign in" />
- <label for="checkbox"><input type="checkbox" id="checkbox" />Remember me</label>
- </fieldset>
- <span><a href="#">Forgot your password?</a></span>
- </form>
- </div>
- </div>
- <!-- Login Ends Here -->
- </div>
- </div>
- </body>
- </html>
Now run the application and test it.
Now click on the login image to show a login drop-down with Twitter style.
Note: You can see a demo of this article by downloading this application.
Some Helpful Resources