Javascript/JQuery 使用 div/"grippie" 调整文本区域的大小
Javascript/JQuery resize textarea with div/"grippie"
我看了很多内容,包括如何制作一个 "grippie" 来调整 textarea
的大小,并且尝试了所有代码,但 none 成功了。有什么帮助吗?当您提出问题或 post 回答时,我正在努力使它像 Stack Overflow 上的那样。
Controlling Stacking on Webpage
你有两个 div
<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>
使用 ondragstart 连接 grippie
$('#grippie').on('dragstart', 函数(evt) {
})
如果用户点击顶层而不是 grippie setfocus on the textarea
我知道怎么做了!! Here 是一个 fiddle 的项目。我会继续更新,让它变得更好!
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;
}
我看了很多内容,包括如何制作一个 "grippie" 来调整 textarea
的大小,并且尝试了所有代码,但 none 成功了。有什么帮助吗?当您提出问题或 post 回答时,我正在努力使它像 Stack Overflow 上的那样。
Controlling Stacking on Webpage
你有两个 div
<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>
使用 ondragstart 连接 grippie
$('#grippie').on('dragstart', 函数(evt) {
})
如果用户点击顶层而不是 grippie setfocus on the textarea
我知道怎么做了!! Here 是一个 fiddle 的项目。我会继续更新,让它变得更好!
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;
}