简体   繁体   中英

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.

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;
}

Controlling Stacking on Webpage
You have two divs

<div id="div1" class="bottom-layer"><textarea></textarea></div>
<div id="div2" class="top-layer"><img id="grippie" src="grippie.png"  draggable="true"  class="grippie-thingy"/></div>

Using ondragstart wire up the of grippie

$('#grippie').on('dragstart', function(evt) {

})

If the user clicks the top-layer and not the grippie setfocus on the textarea

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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