July 23, 2010

Expand a TextBox on Focus using jQuery




Here’s how to animate and expand the height and width of a TextBox when it receives focus. After a delay, the TextBox returns to its normal size

<html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
title>Expand a TextBox on Focus in jQuery</title>
<
style type="text/css">
.txt
{
width:100px;
height:15px;
}
</style>
<
script type="text/javascript"
src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js">
</
script>

<
script type="text/javascript">
$(function () {
$(".txt").focus(function () {
$(this).animate({
width: '200px',
height: '40px'
},
"slow"
)
.delay(2000)
.animate({
width: '100px',
height: '15px'
},
"slow"
);
});
});
</script>
</
head>
<
body>
<
div>
<
input class="txt" type="text"
value="Some Text Some Text Some Text" /><br />
</
div>
</
body>
</
html>

The code is self explanatory. We first animate the height and width of the TextBox and increase its size. We then set a delay() and then animate the height and width back to what it was earlier.

See a Live Demo



'Like' us on our FaceBook page if you find this blog useful. Thanks!


Did you like this post?
kick it on DotNetKicks.com Save on Delicious
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

0 Responses to "Expand a TextBox on Focus using jQuery"
 

Copyright © 2009-2012 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions