Okay, to do this with native JS you have to take a few steps.
By order will be:
- Tying event dropper for mousedown
- event wrapping event for mousemove
- make the bar have position: absolute
- give top position equal to mouse position
- compute the corner coordinate of
ul
- calculate the difference between this coordinate and the mouse position
- give the div height this difference.
In code this might look like this:
window.onload = addListeners;
function addListeners(){
document.querySelector('.resize').addEventListener('mousedown', mouseDown, false);
window.addEventListener('mouseup', mouseUp, false);
}
function mouseUp(){
window.removeEventListener('mousemove', divMove, true);
}
function mouseDown(e){
window.addEventListener('mousemove', divMove, true);
}
function divMove(e){
var div = document.querySelector('.resize');
div.style.position = 'absolute';
div.style.top = e.clientY + 'px';
var altura = div.previousElementSibling.getBoundingClientRect().top;
div.previousElementSibling.style.height = (e.clientY - altura) + 'px';
}
Example: link