Teacher of Things Teacher of Things - 2 months ago 10
Javascript Question

Javascript/JQuery resize textarea with div/"grippie"

I've look at many things covering how to make a "grippie" that resizes a

textarea
, and have tried all the code but none was worked. Any help? I'm trying to make it like the one on Stack Overflow when you ask a question or post an answer.

Answer

I found out how to do it!! Here is a fiddle with the project. I will continue to update it and make it better!

HTML

<textarea id="textarea"></textarea>
<div id="grippie" draggable="false"></div>

QJuery/JavaScript

var resize = false;
$('#textarea').hover(function(e){
    e.preventDefault();
    resize = false;
});
$('#grippie').mousemove(function(e){
    if(resize == true){
      $('#textarea').height(e.pageY-18);
   }
});
$('#grippie').mousedown(function(e){
    resize = false;
   resize = true;
});
$(window).mouseup(function(e){
   resize = false;
});

CSS

#textarea {
   padding: 2px;
   width: 400px;
   height: 200px;
   min-height: 50px;
   overflow: auto;
   resize: none;
}
#grippie {
   display: block;
   width: 404px;
   height: 5px;
   background-color: #CCC;
   border: 1px solid #888;
   cursor: s-resize;
}
Comments