簡體   English   中英

以平滑的方式更改Textarea尺寸

[英]Change Textarea size in a smooth way

我想實現這樣的效果:當用戶將一個文本區域聚焦在一個表單中時,它會變得更高,在模糊時會達到它的原始大小。 這就是我到目前為止所做的: http//jsfiddle.net/jRYDw/

我的代碼:

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

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

我想做的是讓textarea以平滑的方式擴展,這可能嗎?

我不得不使用動畫功能

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

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

您可以指定動畫的長度,緩動函數以及動畫完成時的回調。

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

參考 - http://api.jquery.com/animate/

DEMO

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM