JSFiddle - React, Tailwind, and code Playground
HTML
<div id="resizableCanvas" style="width: 200px; border: 1px solid red; height: 50px; overflow: auto; position:relative;">
<div id="results">
test
</div>
<div style="height:5px; background-color:red; position:absolute; left:0; right:0; bottom:0;" class="panel-resize-handle">
</div>
</div>
JavaScript
// create an observer instance
var target = document.querySelector('#resizableCanvas');
console.log(target);
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
document.querySelector("#results").innerHTML = 'input text changed: "' + mutation.attributeName + '"';
console.log(mutation, mutation.type);
});
});
observer.observe(target, { attributes: true, filter:['height'] });
//observer.disconnect(); - to stop observing
makePanelDraggable(target);
function makePanelDraggable(panel) {
var currentElement = null;
var mouseMoveHandler = function (event) {
event.preventDefault();
var newHeight = (+currentElement._startHeight + (+event.pageY - +currentElement._startY));
panel.style.height = newHeight + 'px';
}
var mouseUpHandler = function (event) {
currentElement = null;
document.removeEventListener( 'mousemove', mouseMoveHandler);
document.removeEventListener( 'mouseup', mouseUpHandler);
}
for (var i in panel.childNodes) {
var element = panel.childNodes[i],
tag = element.nodeName ? element.nodeName.toUpperCase() : false;
if (tag === 'DIV' && element.classList.contains('panel-resize-handle')) {
element.addEventListener('mousedown', function (event) {
event.preventDefault();
currentElement = this;
this._startY = event.pageY;
this._startHeight = panel.style.height.replace('px','');
console.log(this._startY);
console.log(this._startHeight);
document.addEventListener('mousemove', mouseMoveHandler);
document.addEventListener('mouseup', mouseUpHandler);
});
}
}
}