how to expand a text area when click on

后端 未结 9 1289
感情败类
感情败类 2021-02-02 10:17

Im working on a small project which has a textarea and i need help in making the text area expand on mouse click like that of twitter and facebook. the textarea should look lik

相关标签:
9条回答
  • 2021-02-02 10:44
    $("textarea").focus(function(){
        $("textarea").animate({ height: "70px" }, 500);
    });
    

    default css

    textarea{ height: 50px;}
    

    on focus textarea height will increase :) simple jquery

    0 讨论(0)
  • 2021-02-02 10:45
    <textarea style="width:200px; height:50px;" id="ta"></textarea>
    
    var ta = document.getElementById('ta');
    ta.onclick = function(){
        this.style.height = "400px";
    }  
    

    A quick fiddle: http://jsfiddle.net/n6sgT/

    0 讨论(0)
  • 2021-02-02 10:46

    Something like this would work...

    Demo: http://jsfiddle.net/Y3rMM/

    CSS...

    .expand {
        height: 1em;
        width: 50%;
        padding: 3px;
    }
    

    HTML...

    <textarea class="expand" rows="1" cols="10"></textarea>
    

    jQuery...

    $('textarea.expand').focus(function () {
        $(this).animate({ height: "4em" }, 500);
    });
    
    0 讨论(0)
提交回复
热议问题