http://jsfiddle.net/Calum/5dqwJ/
CSS:
textarea {
height: 20px;
margin: 20px;
width: 585px;
resize: none;
overflow: hidden;
vertical-align: top;
transition: height 3s;
-webkit-transition: height 3s;
-moz-transition: height 3s;
-o-transition: height 3s;
}
Javascript:
$(document).ready(function () {
$("textarea").focus(function (event) {
if ($(this).val().length === 0) {
$(this).height(100);
$(this).css('resize', 'vertical');
$(this).attr('placeholder', null);
}
});
$("textarea").blur(function (event) {
if ($(this).val().length === 0) {
$(this).height(20);
$(this).attr('placeholder', "Enter comment");
$(this).css('resize', 'none');
}
});
});
HTML:
<textarea placeholder='Enter comment'></textarea>
In Chrome, IE and Opera, when you focus on the textarea it expands and contracts with the CSS3 transition.
When I do the same with FireFox, it doesn’t animate anything.
Any ideas why?
Thanks!
If you add the
requiredattribute on your textarea, you could use the:invalidpseudo-class to target an empty textarea:demo
(add
box-shadow: none;if you don’t want the red border around it)