Well, the closest I could do was using the mousemove
event.
I detect if the% div is coaxed to increase the size of the .drag
according to the position I'm 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 textarea
is set, I'd particularly use height
and Math.min
to set the minimum and maximum size the element could reach in height.