Well, the closest I could do was using the event mousemove
.
I detect if div .drag
was triggered to increase the size of the textarea
according to the position I am moving the mouse (up or down)
window.addEventListener('load', function () {
var lastPageY = 0;
var textarea = document.querySelector('textarea');
var drag = document.querySelector('.drag');
drag.addEventListener('mousedown', function () {
drag.classList.add('active');
}, true);
document.addEventListener('mousemove', function (e) {
var dragEnabled = drag.classList.contains('active') && e.which === 1;
if (! dragEnabled) return;
// Movimento continua na mesma posição anterior. Então nada é feito
if (e.pageY === lastPageY) return;
// posição da página atual menos o tamanho do .drag
var height = e.pageY - drag.offsetHeight;
textarea.style.height = height + 'px';
// salva a posição anterior :)
lastPageY = e.pageY;
})
window.addEventListener('mouseup', function (e) {
drag.classList.remove('active');
console.log('stopped');
}, false)
})
*{box-sizing: border-box; }
.drag
{
background-color: #ddd;
width: 100%;
user-select:none;
text-align: center;
font-size: 20px;
display: flex;
height: 15px;
justify-content: center;
align-items: center;
}
.drag.active{
background-color: #049;
cursor: move;
color: white;
}
.container textarea{
display: block;
resize: none;
width: 100%;
user-select: none;
}
<div class="container">
<textarea></textarea>
<div class="drag">
• • •
</div>
</div>
In the part where the height
, I would particularly wear a Math.min
and Math.max
to define the minimum and maximum size that the element could reach height.
Good night! I copied from the site itself here! "Stackoverflow" tested and worked, but in the corner. <! -- Begin snippet: js Hide: false console: true Babel: false --> <!-language: lang-html --> <textarea id="wmd-input" class="wmd-input wz-element s-input bar0 processed" name="post-text" cols="52" Rows="15" tabindex="80" data-wz-state="8" data-min-length="" style="opacity: 1; height: 43px;"></textarea> <!-- end snippet -->
– Ag Soft
Short answer: will have to use Javascript
– Wallace Maxters
With jQuery UI you get it easy. If you want I can post an example.
– Sam
Could you give me a simple example with comments explaining?
– Mark Vaaz
You can see here with comments: https://jsfiddle.net/kcth8j5v/11/
– Sam