Javascript/JQuery resize textarea with div/“grippie”

感情迁移 提交于 2021-02-10 13:16:53

问题


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.


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/37736223/javascript-jquery-resize-textarea-with-div-grippie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!