Loading Searchbox
9lessons programming blog logo
Monday, December 14, 2009

Twitter like Login with Jquery and CSS.

21 comments
In this post I want to explain "Twitter like login hide and show effect with jquery and CSS ". Very simple just five line of code using jquery hide() and show() events and little CSS code, use it and enrich your web projects. Take a look at live demo.

Twitter like Login with Jquery and CSS.

Twitter API: Up and Running: Learn How to Build Applications with the Twitter API

Download Script     Live Demo

Javascript Code
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js
"></script>
<script type="text/javascript">
$(document).ready(function()
{

$(".sign_in").click(function()
{
$("#sign_box").show();
return false;
});
$("body #main").click(function()
{
$("#sign_box").hide();
return false;
});
});
</script>



HTML Code
$('.sign_in').click(function(){} - sign_in is the class name of anchor 'Sign In'. Using show() event displaying the id="sign_box".
<div><a href="#" class="sign_in">Sign In</a></div>
<div id="sign_box">
<form method="post" action="">
<label>UserName
<input type="text" name="usr"/></label>
<label>Password
<input type='password' name="pwd"/></label>
<input type="submit" value=" Sing In "/>
</form></div>
<div id='main'><h1>9lessons.blogspot.com</h2></div>

CSS code
Contains CSS code just find out position:absolute
#sign_box
{
width:170px;
background-color:#fff;
border:solid 1px #5ea0c1;
padding:8px;
position:absolute;
display:none;
-moz-border-radius-topright:6px;
-moz-border-radius-bottomleft:6px;
-moz-border-radius-bottomright:6px;
-webkit-border-top-right-radius:6px;
-webkit-border-bottom-left-radius:6px;
-webkit-border-bottom-right-radius:6px;
}
.sign_in
{
background-color:#FFFFFF;
border:solid 1px #5ea0c1;
padding:6px;
}
#main
{
height:500px;
}
Sponsored Links

Recent Posts

Share this post

Subscribe to my feeds

Subscribe
Comments
21 comments
Farid S said...

thanks for sharing this tut:)

Lucifix said...

You know what would be nice, to hide login menu with click on Signin text ;)

ankit said...

Hey Sory, i m noob but wat these code do?

-moz-border-radius-topright:6px;
-moz-border-radius-bottomleft:6px;
-moz-border-radius-bottomright:6px;
-webkit-border-top-right-radius:6px;
-webkit-border-bottom-left-radius:6px;
-webkit-border-bottom-right-radius:6px;

Srinivas Tamada said...

@ankit

Code for round corners - topright, bottomleft, bottomright

Thomas said...

Here's some quick feedback:

Please don't leave the for attribute off of your label tags. You're hurting the Internet every time you do.

Also, writing your code so that clicking on "sign in" with JavaScript disabled would take you to an independent login URL would also be wonderful.

Twitter's sign in drop down does both of these things, by the way.

9tips said...
This post has been removed by the author.
Ravi Kumar Tamada said...

Great good one. Keep blogging.

Fábio Luciano said...

Hi, feedbacking:
make this, to have use of label tag

[label]Password [input type='password' name="pwd"/][/label]

junal said...

Well, nothing is click-able inside the #sign_box - Any idea?

Srinivas Tamada said...

@junal

I did little code modification.

Gustavo said...

if you like to close the box clicking back on Sign In link, you can use the toggle fuction for jquery.

Bob MacNeal said...

I modified the click event on sign_in from show to toggle... so that clicking sign_in toggles sign_box.
Cheers.

Florian said...

I've tried to click the 9lessons.blogspot.com link and it doesn't work because of the close event (i think)! Any suggestions on this?

Fábio Luciano said...

Hi friend,

thanks to accept the modification in the code.

Xanti SS said...

Now tell me, why is jQuery needed here?

Kaido said...

Simple and effective solution :) Super.. I used more advanced solution found at http://aext.net/2009/08/perfect-sign-in-dropdown-box-likes-twitter-with-jquery/ but I belive yours simpler to use :) I used this with Drupal at http://jkvandra.ee

Andrew Woo said...

What if you need to do have people login securely via HTTPS?

Neha said...

@Bob MacNeal or @shrinivas

I would like to close the box clicking back on Sign In link. Could you please tell me how can i do that?

Anonymous said...

hell yeah!
plzzz.... post the codes for hiding the box also...thank u;

Mangesh said...

Ultimate mate.......

Nanosoft said...

Here is the code for closing the box when you click on Sign in:

$(".sign_in").click(function(){
if ($("#sign_box:visible").length != 0){
$("#sign_box").hide();
}
else {
$("#sign_box").show();
}
return false;
}

Post a Comment

Orkut | FacebookAbout Me

Subscribe now!Feeds RSS

Subscribe now!Recent Posts

Subscribe now!Categories

Subscribe now!Comments

People Says

@9lessons thank you for the great tutorials, we truly appreciate your contributions to the design community.

Smashing Magazine

Join into my community

Labs ProfileRelease

My ProfileTwitter