简体   繁体   English

以平滑的方式更改Textarea尺寸

[英]Change Textarea size in a smooth way

I want to achieve this effect: When the user focus a text area within a form, it gets higher, on blur gets to it's original size. 我想实现这样的效果:当用户将一个文本区域聚焦在一个表单中时,它会变得更高,在模糊时会达到它的原始大小。 This is what I have done so far: http://jsfiddle.net/jRYDw/ 这就是我到目前为止所做的: http//jsfiddle.net/jRYDw/

My code: 我的代码:

$('textarea').focus(function(){
    $(this).css('height','80px');
});

$('textarea').blur(function(){
    $(this).css('height','40px');
});

What I want to do is to make the textarea expands in a smooth way, is that possible? 我想做的是让textarea以平滑的方式扩展,这可能吗?

I had to use animate function 我不得不使用动画功能

$('textarea').focus(function(){
    $(this).animate({height:'80px'});
});

$('textarea').blur(function(){
    $(this).animate({height:'40px'});
});

You can specify the length of the animation, easing function and also a callback for when the animation is complete. 您可以指定动画的长度,缓动函数以及动画完成时的回调。

.animate( properties [, duration] [, easing] [, complete] ) .animate(properties [,duration] [,easing] [,complete])

Reference - http://api.jquery.com/animate/ 参考 - http://api.jquery.com/animate/

DEMO DEMO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM