0

单击文本区域后,我需要将文本区域的高度更改为 60px 并同时向下滑动,这样看起来就像一个流畅的动画。

这是 JSFiddle:http: //jsfiddle.net/MgcDU/6399/

HTML:

<div class="container">
  <div class="well">
      <textarea style="width:462px" placeholder="Comment..."></textarea>
  </div>
</div>

谢谢。:)

4

4 回答 4

1

这样的东西?

$('#comment').click(function() {

   $(this).css('height', '60px');

});
于 2013-08-04T00:59:31.790 回答
1

您需要的方法称为animate()并且有据可查。

现在为了你的小提琴,我编写了演示 animate 方法以及 focus() 和 blur() 方法的 jQuery 代码:

jQuery(document).ready(function ($){

    var element = $('.well textarea');
    var orig_height = element.height();
    var new_height = 60;

    // onfocus event handler
    element.focus(function (){
        $(this).animate({height: new_height + 'px'});
    });
    // onblur event handler
    element.blur(function (){
        $(this).animate({height: orig_height + 'px'});
    });
});
于 2013-08-04T01:10:50.973 回答
0

它作为动画效果更好......

$("textarea").on('focus',function (e, ui) {
    $(this).animate({
        height: "60px"
    }, 1500);
});

jsFiddle 演示

于 2013-08-04T01:19:24.713 回答
0
$('#comment').click(function () {

   $(this).fadeIn(3000, function() {
      $(this).css('height', '60px');
   });


   $(this).focusout(function() {
      $(this).css('height', '20px');
   }); 



});
于 2013-08-04T01:20:48.223 回答